Explore topic-wise InterviewSolutions in Current Affairs.

This section includes 7 InterviewSolutions, each offering curated multiple-choice questions to sharpen your Current Affairs knowledge and support exam preparation. Choose a topic below to get started.

1.

What do you know about a VPN (Virtual Private Network)? What are the many types of virtual private networks (VPNs)?

Answer»

A virtual private network (VPN) connects users' computers to a private network across a PUBLIC network, allowing them to send and receive data as if they were physically connected to the private network. USING a VPN gives you more capability, security, and control over your private network. Telecommuting professionals typically use it to acquire access to resources that aren't available on the public network. Although encryption is common, a VPN connection does not require it. A VPN is created by creating a virtual point to point connection over existing networks utilising dedicated circuits or tunnelling technology. Some of the advantages of a wide area network can be acquired by connecting to a VPN over the public Internet (WAN). From the user's perspective, the resources supplied within the private network can be accessed remotely.

The following are the various types of VPNs:

  • Site to Site VPN: A Site to Site VPN, also known as a Router to Router VPN, joins the networks of two offices in different locations. There are two subcategories, as indicated below:
    • Intranet VPN: Intranet VPNs are used for connecting remote offices in various locations utilising one single infrastructure, that is, the servers, internet connectivity, etc., as a private WAN and the same accessibility POLICIES (wide area network).
    • Extranet VPN: Extranet VPN uses common infrastructure to connect intranet users, suppliers, consumers, partners, and other entities via dedicated connections.
  • Access VPN: An access VPN is a sort of virtual private network that allows mobile users and telecommuters to connect to the internet from a remote location. Dial-up or ISDN (Integrated SERVICES Digital Network) connections can be REPLACED with it. It's a budget-friendly alternative with a variety of connectivity possibilities.
Useful Interview Resources
  • Free Mock Coding Interview
  • Coding Interview Questions for Practice
  • Technical Interview Questions for Practice
  • Interview Preparation
2.

Give the definition of abstract classes. Can we make objects or instances of these classes?

Answer»

An abstract class is a type of class that has abstract methods. The abstract CLASSES do not DEFINE these methods, despite the fact that they are declared. These methods must be PROVIDED in a subclass only if they are to be used in that subclass.

No, we can't make abstract classes into objects or instances. There can be no instances of an abstract class since it LACKS a complete implementation. Subclasses that inherit the abstract class can be used to create instances.

3.

State the delivery guarantees with the following techniques in Distributed systems: best effort, at least once, at most once?

Answer»

In distributed systems, the following are some common "message delivery approaches":

  • At Most Once: When sending a message from the sender to the receiver via at-most-once message delivery, there is no guarantee that they will receive it. Not all messages will be sent, and if you try to solve the problem yourself by ATTEMPTING delivery at least once or using a different mechanism like batching, you will fail.
  • At Least Once: The at-least-once strategy to sending communications means that either the sender or the recipient of a message must actively participate and ensure that there is no way of knowing if it will be received every time they transmit it. To ensure that each message is sent, either the sender must notice a failure and resend the message, or the receiver must continually REQUEST messages that have not been delivered. The message recipient might be either a sender who continues to send messages until they obtain a response or someone who refuses to give up and KEEPS dragging them in.
  • Exactly Once: With the at-least-once messaging strategy, we can only hope that our processes result in certain messages being delivered several times. Ideally, we'd like to have messages delivered exactly once. However, life isn't always FAIR, and you can't always get what you want!
4.

Discuss the various types and subtypes of Design Patterns known to you.

Answer»

The various types and subtypes of DESIGN Patterns are as follows:

Creational Design Patterns: It is all about class instantiation in these design patterns. This pattern can be further subdivided into patterns for creating classes and patterns for creating objects. While class creation patterns make good use of inheritance in the instantiation process, object-creation patterns make good use of delegation. They can be of the following types:

  • Abstract Factory: Creates an instance of various classes from different families.
  • Builder: It distinguishes between the construction of an object and its depiction.
  • Factory Method: Creates a new instance of a collection of derived classes.
  • Object Pool: By recycling objects that are no longer in use, expensive ACQUISITION and release of resources is avoided.
  • Prototype: An instance that has been fully initialised and is ready to be duplicated or cloned.
  • Singleton: There can only be one instance of a class.

Structural Design Patterns: It is all about Class and Object composition in these design patterns. Inheritance is USED to construct interfaces in structural class-creation patterns. Structural object patterns define how to put objects together to get new functionality. They can be of the following types:

  • Adapter:  It combines interfaces from various classes.
  • Bridge: It separates the interface of an object from its implementation.
  • Composite: Simple and composite things are arranged in a tree structure.
  • Decorator: It assigns responsibilities to objects in a dynamic fashion.
  • Facade: An complete subsystem is represented by a single class.
  • Flyweight: For efficient sharing, a fine-grained instance is used.
  • Private Class Data: Accessor/mutator access is restricted in it.
  • Proxy: In it, an object is a representation of another object.

Behavioural Design Patterns: The communication of Class objects is the focus of these design patterns. Behavioural patterns are those that are primarily concerned with object-to-object communication. They can be of the following types: 

  • Chain of responsibility: A method of forwarding a request from one object to the next in a chain of objects.
  • Command: As an object, encapsulate a command request.
  • Interpreter: A method of incorporating language components into a program.
  • Iterator: Access the items of a collection in a LOGICAL order.
  • Mediator: It is used for defining simplified communication between classes.
  • Memento: Capture and restore the internal state of an object
  • Null Object: Designed to serve as a default value for an object
  • Observer: A method of informing a large number of classes about a change.
  • State: When an object's state changes, alter its behaviour.
  • Strategy: Inside a class, a strategy encapsulates an algorithm.
  • Template Method: Delegate the algorithm's precise steps to a subclass.
  • Visitor: It adds a new operation to a class without making any changes to it.
5.

What do you understand about Design Patterns? What are their uses?

Answer»

A design pattern is a generic repeatable solution to a typically occurring problem in SOFTWARE design in software engineering. A design pattern isn't a finished design that can be TURNED into code right away. It is a description or template for solving an issue that may be applied to a variety of scenarios.

Patterns in Design are used in a variety of ways. Design patterns can help developers save time by providing tried and true DEVELOPMENT paradigms. Effective software design necessitates taking into account challenges that may not be apparent until later in the implementation process. For coders and architects familiar with the patterns, REUSING design patterns helps to eliminate subtle flaws that can lead to large difficulties and improves code readability. People FREQUENTLY only know how to apply certain software design techniques to specific situations. These methods are challenging to apply to a broader set of issues. Design patterns are generic solutions that are documented in a way that does not necessitate specifics connected to a specific situation. Patterns help engineers to speak about software interactions using well-known, well-understood terms. Compared to ad-hoc designs, common design patterns can be improved over time, making them more robust.

6.

Highlight some of the drawbacks of inheritance.

Answer»

The following are some of the drawbacks of inheritance:

  • Looking at DIFFERENT classes for different purposes frequently increases the amount of time and EFFORT required to complete a program.
  • The classes of parent and kid become closely intertwined.
  • Any program adjustments would ENTAIL revisions in both parent and child classes.
  • It demands meticulous implementation; else, INCORRECT OUTCOMES will happen.
7.

Explain the benefits and drawbacks of Object-Oriented Programming Languages.

Answer»

Some of the benefits of adopting Object-Oriented Programming Languages are as follows:

  • Object-Oriented Programming Languages (OOPS) are programming languages that employ a bottom-up approach, allowing programmers to replicate the real world and its constituents.
  • Object-Oriented Programming Languages reduce the amount of code that programmers have to write.
  • Code may be easily changed and extended without impacting other capabilities.
  • Object-Oriented Programming Languages demand a long and thorough design phase, which results in a better design with FEWER faults.
  • It makes code reusability possible.
  • Object-Oriented Programming Languages (OOPLs) help programmers achieve their objectives faster.
  • Object-Oriented Programming Languages (OOPLs) are languages that break down a large problem into smaller pieces.
  • When abstraction is APPLIED, the user is not exposed to SUPERFLUOUS data.

Some of the drawbacks of utilising Object-Oriented Programming Languages are as follows:

  • It takes a lot of planning to use these languages effectively.
  • These aren't ideal for little concerns because they complicate things too much.
  • Classes in Object-Oriented Programming Languages have a tendency to be OVERLY wide.
  • In some situations, programs written in Object-Oriented Programming Languages may consume a significant amount of memory, which is obviously undesired.
8.

What do you know about demand paging in operating systems?

Answer»

Demand paging in operating systems is a strategy for LOADING pages (a PAGE is the smallest unit of data for memory management in a virtual memory operating system). A page frame is the smallest contiguous unit of physical memory with a predetermined length into which the operating system maps memory pages) only when they are needed. Virtual Memory is a storage allocation method that MAKES it possible to address secondary memory as if it were the main memory. The addresses used by a program to refer to memory are different from the addresses used by the memory system to designate physical storage sites, and the addresses created by the program are automatically converted to machine addresses. The quantity of secondary memory available is defined by the number of main storage sites available rather than the actual number of main storage locations, and the capacity of virtual storage is restricted by the computer system's addressing scheme.

When a place on the page is addressed during execution, the page is only brought into memory. The following are the steps for getting a page into the main memory or demand paging:

  • An attempt is MADE by the operating system to visit the page.
  • If the page is valid, the CPU proceeds to process instructions as usual (in memory).
  • When a page is wrong, the operating system performs a page fault trap.
  • The operating system then examines the memory reference to see if it is a valid reference to a secondary memory location. The process will be cancelled if this is not the case (illegal memory access). Otherwise, the operating system will have to read the page from the main memory.
  • The operating system ARRANGES a disc operation to read the desired page into the main memory.
  • The operation that was paused as a result of the operating system trap is then restarted or continued.
9.

Give a list of the different types of operating systems you are familiar with. Include some examples of each type of operating system as well.

Answer»

The following are some of the several types of operating systems:

  • Distributed Operating Systems: A distributed operating system (DOS) is software that manages numerous computers as if they were one.
  • Batch Operating System: This operating system INTERACTS with the computer indirectly. There is a worker who organises linked jobs into batches based on their requirements. It is the operator's responsibility to group jobs that have COMPARABLE needs together.
  • Real-Time Operating Systems: Real-Time Operating Systems (RTOS) are employed in situations when a significant number of events, the bulk of which are external to the computer system, must be accepted and processed quickly or within a tight deadline. Industrial control, telephone switching equipment, aircraft control, and real-time simulations are examples of such uses.
  • Network Operating Systems: Network Operating Systems allow computers with different operating systems to JOIN the same network. It's routinely used in the name of security.
  • Time-Sharing Operating System: A time-sharing operating system allows numerous people to use the same computer at the same time. This operating system makes the most of the available resources.

Some examples of operating systems are as follows:

  • Microsoft Windows is an operating system DEVELOPED by Microsoft (Graphical User Interface Operating System based for PERSONAL Computers)
  • iOS is Apple's mobile operating system (iPhone, iPad, and iPod Touch operating system)
  • MacOS is the operating system that runs on Apple's personal computers and workstations, such as the MacBook and iMac.
  • GNU or Linux (for Personal Computers, File and Print server, Workstations, ISP, Three-tier Clients and Servers)
  • Android (Google's mobile operating system for smartphones, tablets, smartwatches, and other devices) is a mobile operating system developed by Google.
10.

What exactly is a Bootstrap Program in terms of operating systems?

Answer»

A Bootstrap Program is typically a program that initialises the operating system during the startup of a computer system, in other words, the first program that runs when a computer system starts up. Booting is a METHOD or application for loading the operating system. Overall, the bootstrap program is completely responsible for the operating system's performance and functionality. It is totally stored in boot blocks at a specific spot on the DISC. It also locates and loads the kernel into the main MEMORY before starting the program. The Bootstrap Program, as shown in the figure below, LIES in the Read-Only Memory (ROM) of our COMPUTERS and is responsible for reading the Operating Systems and loading them into the RAM (Random Access Memory) of our computers. After then, the operating systems can start other computer devices such as graphics cards, keyboards, and mice.

11.

State a few advantages of multithreaded programming.

Answer»

The FOLLOWING are some of the advantages of multithreaded programming:

  • Multithreaded programming increases the SYSTEM's responsiveness to consumers.
  • In multithreaded programming, there is resource sharing INSIDE the process.
  • It takes full ADVANTAGE of the multiprocessing architecture.
  • Because parallel processing is performed in a way, it is cost-effective in TERMS of the resources needed in the project.
12.

What is the definition of a single point of failure in a distributed system?

Answer»

Any component in a SYSTEM that fails and renders the ENTIRE system worthless is known as a single point of failure. For instance, a computer that uses RAID storage can keep running even if one of its discs fails. We also have websites that replicate application servers on a wider scale. They, too, maybe vulnerable to SPOFS, as one server may go down with all data INTACT while the rest of the system remains operational.

13.

In distributed systems, what do you understand about the fundamental model?

Answer»

Distributed systems are fragile and sophisticated. These models assist DESIGNERS in RESOLVING major design concerns, obstacles, or risks so that they can construct a system that is both dependable and secure without losing any of its proper objectives, such as bandwidth optimization for performance reasons. Firewalls and ACLs govern network traffic flow via them; Access Control Lists restrict who has access based on rules defined by users inside their respective organisations' POLICIES. These are examples of the fundamental models being referred to. These controls ensure that DATA does not LEAK outside of an organization's firewall while simultaneously giving it some control.

14.

What are distributed systems? State some examples of distributed systems.

Answer»

Distributed systems are a sort of software environment or computer system in which various components are distributed among multiple computing devices (or other devices) through the INTERNET. These networks divide and coordinate the work so that it MAY be accomplished more quickly than if one computer or device handled everything alone. It simply implies "distributed" as opposed to "centralised" or having a single point of contact for all communications and processing amongst computing equipment. Distributed file systems, for example, allow computer applications to see SEVERAL physical storage devices, such as disc drives, as a single huge storage resource. ALTHOUGH the distributed operating system handles different resources, it appears to users as a single entity with its own namespace (e.g., files are given names independent of their location). By utilising dispersed resources to increase data locality, distributed systems have the potential to achieve excellent performance and availability. Because it provides concurrent processing capacity of all computers involved, distributed computing allows us to attain larger scalability than a single computer could, offering redundancy against equipment failures or scheduled maintenance downtime. A distributed architecture usually entails distribution across physical HARDWARE, which is more complicated but has advantages over sharing a single large server, such as the ability to use specialised hardware designed to improve computational efficiency, reliability, and fault tolerance while also allowing applications to use computing resources located close together (reducing latency).

The following are some of the most common distributed system examples:

  • A Distributed System is exemplified by the telephone system and cellular networks.
  • The World Wide Web is another distributed system that allows people to connect with one another via computers all over the world, creating a virtual community in which anything can happen.
  • Computation in parallel is an example of a Distributed System.
  • Aircraft control systems use similar ideas, combining data from multiple sources to tell planes not only where they're heading but also how fast or slow they should fly based on wind conditions and other factors.
  • BitTorrent and other peer-to-peer networking apps (for downloading).
15.

How does OpenMP make it possible to program in shared memory?

Answer»

To control the automatic creation of THREADS in OpenMP, pragmas are used. The threads share memory because they share the ADDRESS SPACE. They do, however, have access to a local view of the shared variables via "private" variables. Each thread gets its own variablecopy, which the compiler can optionally initialise with the ORIGINAL variable. The references to private variables are statically UPDATED to the new variables within the thread.

16.

Define cache coherence and hypercube connection. For a node hypercube, what will be its diameter?

Answer»

Cache coherence simply MEANS that different processors might keep their own local caches. As a result, there could be several copies of the same data. Access to the local copies BEHAVES similarly to access from the local copies, with the exception of access time. A hypercube is a single node. An n node hypercube is made up of two n/2 node hypercubes connected by their RESPECTIVE nodes. An n node hypercube has a DIAMETER of log(n). The diameter is nothing but the smallest number of links needed to connect the two farthest nodes.

17.

What do you understand about SMID?

Answer»

SMID stands for single instruction multiple data and is a class in Flynn's taxonomy of parallel architectures. Different processing elements in this architecture all execute the same instruction in the same CLOCK CYCLE, with the RESPECTIVE data (e.g., in REGISTERS) being independent of one another.

18.

What do you understand about the Shared memory and NUMA memory architecture?

Answer»

Shared MEMORY architectures are those in which all execution THREADS have access to the same address SPACE. NUMA STANDS for Non-Uniform Memory Access, and it's a type of shared memory architecture in which a processor's access times to different memory LOCATIONS, as well as access times to the same memory location by multiple processors, can differ.

19.

In the context of operating systems, define microkernels.

Answer»

One of the kernel's classes is the microkernel. Because it is a kernel, it is in charge of all system resources. In a microkernel, however, user and kernel services are implemented in separate address zones. Because user services are PLACED in user address SPACE and kernel services are located in kernel address space, the kernel and operating system are both smaller. It just offers the MINIMAL essentials in terms of process and memory management. The execution microkernel is slowed by message forwarding, which is used to establish communication between client programs/applications and services executing in user address space. Because user and kernel services are separated, the Operating System is unaffected if one fails. As a result, one of the microkernel's advantages is enhanced. It's simple to extend since new services are added to the user address space rather than the kernel address area, requiring no kernel changes. It's also portable, secure, and dependable. The architecture of a microkernel is SHOWN below:

The following are some of Microkernel's advantages:

  • This kernel performs better because of its compact and isolated architecture.
  • The system can be expanded more easily since it can be added to the system application without DISRUPTING the kernel.
20.

List some of the benefits of Java Packages.

Answer»

The following are some of the BENEFITS of Java Packages:

  • Using packages prevents NAME collisions in Java.
  • It is a LOT easier to LOCATE the connected classes using packages.
  • The packages MAKE it easier to keep track of who has access to what information.
  • Hidden classes are classes that are not visible outside of the package but are used by it.
21.

How many types of memory areas are allocated by Java Virtual Machine in Java?

Answer»

The following are the several types of memory areas allocated by the Java Virtual MACHINE:

  • CLASS(Method) Area: The Class(Method) Area keeps TRACK of per-class structures such as the runtime constant pool, fields, method data, and method code.
  • Program Counter (PC) Register: The PC (program counter) register stores the address of the Java virtual machine instruction currently being executed.
  • Stack: Frames are kept in the Java Stack. LOCAL variables and partial results, as well as invoking and returning methods, are all managed by it. Each thread has its own JVM stack, which is created at the same time as the thread. A new frame is created each time a method is called. When the method invocation of a frame is complete, it is destroyed.
  • Native Method Stack: The Native Method Stack CONTAINS every single native method utilised in the application.
  • Heap: This is where the objects' memory is allocated during runtime.
22.

Explain the different types of classloaders in Java.

Answer»

Java VIRTUAL Machine or JVM's Classloader subsystem has the responsibility of loading CLASS files. On the execution of a Java APPLICATION, the classloader is loaded firstly. The following are Java's three built-in classloaders:

  • Extension ClassLoader: This is the parent of System ClassLoader and the child of Bootstrap ClassLoader. The $JAVA_HOME/jre/lib/ext directory's jar files are loaded by it.
  • ClassLoader in Bootstrap: ClassLoader is the superclass of Extension classloader, which is the default classloader in Bootstrap. It loads the rt.jar file, which contains all Java Standard Edition class files, INCLUDING java.lang, java.net, java.util, java.io, and java.sql package classes and many more.
  • System or Application ClassLoader: System/Application ClassLoader is an extension classloader's child classloader. The classpath is used to load the class files. By default, the classpath is set to the current directory. To change the classpath, USE the "-cp" or "-classpath" switches. Another name for it is application classloader.
23.

What do you understand about Unary Operations in Relational Algebra with respect to SQL.

Answer»

In Relational Algebra, one operand operations are known as unary operations. The procedures PROJECTION, SELECTION, and RENAME are unary operations in relational algebra:

  • SELECT: The SELECT operation selects a subset of tuples from a relation that fulfils a set of criteria. The SELECT operation is a filter that keeps only those tuples that fulfil a set of criteria. Alternatively, you MAY use the SELECT method to limit the tuples to those that fulfil the criteria. The SELECT operation can be thought of as dividing the relation HORIZONTALLY into two groups of tuples: those that meet the criteria and are selected, and those that do not and are rejected.
  • RENAME: It is occasionally simple and suitable to break a COMPLICATED chain of operations and rename it as a relation with new names. Renaming a RELATIONSHIP can be done for a variety of reasons, including
    • We might want to save the result of a relational algebra expression as a relation so that we can use it later.
    • It's possible that we'll want to join in relation to itself.
  • PROJECT: If a relation is viewed as a table, the SELECT operation selects certain rows while discarding others. In contrast, the PROJECT operation selects a subset of the table's columns while rejecting the remainder. We can use the PROJECT operation to project a relation over just a few of its attributes if we're just interested in a few of them. As a result, the result of the PROJECT operation can be viewed as a vertical partition of the relation into two relations: one with the needed columns (attributes) and the operation's result, and the other with the rejected columns.
24.

State your understanding of Distributed Database Management Systems with Transparency?

Answer»

The transparent Distributed Database Management SYSTEM is a type of database management system that HIDES the physical structure of the database from users. Physical structure, also known as physical storage structure, refers to the memory MANAGER of a database management system and DESCRIBES how data is saved on a disk. There is less ABSTRACTION as a result of this. In Distributed Database Management Systems (or DDBMS), there are four forms of transparency:

  • Transparency in transactions
  • Transparency in performance
  • Transparency in relational databases
  • Transparency in distribution
25.

Define destructors in C++. Give the syntax for Destructors in C++.

Answer»

In C++, DESTRUCTORS are instance member functions that are called automatically when an object is destroyed. A destructor, in other TERMS, is the final function called before an object is destroyed. It's worth noting that if an object was created with the "new" keyword, or if the CONSTRUCTOR USED the "new" keyword to allocate memory from the heap memory or the free store, the memory should be freed with the "delete" keyword in the destructor. Destructors are called for a class object when it goes out of scope or is expressly removed, and they are used to deallocate memory and do the ADDITIONAL cleanup for the object and its members when the object is destroyed.

In C++, a destructor has the following syntax: ~constructorName();

Hence, for instance, if the name of the class is "Complex", the destructor of the class would be as follows (the name of the constructor would be "Complex"):

~Complex();
26.

Explain the concept of Function Overloading with a C ++ code example.

Answer»

Function OVERLOADING is a feature of Object-Oriented PROGRAMMING that allows two or more functions to have the same name but different parameters. When a function name is overloaded with many duties, this is known as function overloading. In Function Overloading, the Function name should be the same, but the ARGUMENTS should be different. Polymorphism is a feature of C++ that allows functions to be overloaded. The following is an example of function overloading in C++:

// including the header files#include <bits/stdc++.h>using namespace std;void printValue(int a) { cout << " Integral Value: " << a << endl;}void printValue(char a) { cout << " Character Value" << a << endl;}void printValue(DOUBLE a) { cout << " Decimal Value " << a << endl;}// MAIN function of the C++ codeint main() { // Calls the integral overloaded function printValue(22); // Calls the character overloaded function printValue("C"); // Calls the decimal overloaded function printValue(231.2322); return 0;}
27.

In C and C++, define inline functions. Also, show how to use an inline function in C.

Answer»

In C or C++, an inline function is one that is declared using the keyword "inline." It has two important features:

  • It is a compiler directive that requests that the compiler replace the body of the function inline by PERFORMING inline expansion, that is, placing the function code at the location of each function call, thus reducing the overhead of a function call (it is not mandatory for the compiler to comply with the REQUEST of the inline function). In this way, it is analogous to the register storage class specifier, which also provides an optimization indication. For frequent calls to the same function, inline functions are typically employed.
  • The second purpose of the keyword "inline" is to change the behaviour of LINKS. The C/C++ separate compilation and LINKAGE architecture necessitates this, in part because the function's definition (body) must be reproduced in all translation units where it is used to allow inlining during compilation, which causes a collision during linking if the function has external linkage (it violates uniqueness of external symbols). In C and C++ (as well as dialects like GNU C and Visual C++), this is handled differently.

An example of an inline function in C is given below:

inline VOID multiply(int x, int y){ int answer = x * y; printf("Product of x and y is the following: %d", answer);}

Let us assume that the above written inline function will be called inside the main function of the C program as follows:

int xval = 5;int yval = 4;multiply(xval, yval);

Here, the "multiply(xval, yval);" function call is going to be replaced in the main function itself by the compiler by the piece of code given below:

int xval = 5;int yval = 4;int answer = xval * yval;printf("Product of x and y is the following: %d", answer);
28.

Differentiate between Call by Value and Call by Reference.

Answer»

Before we look at the key differences between the two, let us take a look at the definitions of Call by Value and Call by Reference:

  • Call by Reference: In Call by Reference, both the actual and formal parameters REFER to the same location, and any changes made within the function are reflected in the caller's actual parameters as a result.
  • Call by Values: The values of actual parameters are copied to the formal parameters of the function in this method of parameter passing, and the two types of parameters are stored in distinct memory areas. As a result, any changes made inside functions are not reflected in the actual arguments passed to the caller.

Now, let us take a closer look at the distinctions between Call by Value and Call by Reference:

CALL BY VALUE CALL BY REFERENCE
The value of each variable in the calling code is transferred into the corresponding parameter variables in the called function in Call by Value.The addresses of the calling function's actual variables are copied into the called function's dummy variables in Call by Reference.
Changes to the parameter variables of the called function will have ZERO impact on the values of the variables of the calling function when using Call by Value.Because the called function receives the addresses of the calling function's actual variables, any changes made to the called function's variables are reflected in the calling function's variables as well.
In call-by-values, we can't change the values of actual variables using function calls.Through function calls, we can change the real values of variables in the call by reference.

The following is an example of each to demonstrate the difference between Call by Value and Call by Reference in C:

Coding Example of Call By Value:

// Illustration of Calling VIA Value using C program#include <stdio.h>// Prototype of the function "subtract"void subtract(float c, float d);// The main function of the C codeint32_t main(){ float a = 71.0, b = 21.0; // Passing a and b and calling the subtract function by Value subtract(a, b); printf("a = %f b = %f\n", a, b); return 0;}// Method DEFINITION to subtract two NUMBERS and store the answer in the first number passedvoid subtract(float c, float d){ c = c - d; printf("c = %f d = %f\n", c, d);}

Output:

a = 50.0 b = 21.0 // Printed value in the subtract functiona = 71.0 b = 21.0 // Printed value in the main function

NOTE: The values of the parameters passed did not change in Call By Value, that is, a remained as 71 and b remained as 21.

Coding Example of Call By Reference:

// Illustration of Calling via Reference using C program#include <stdio.h>// Prototype of the function "subtract"void subtract(float *c, float *d);// The main function of the C codeint32_t main(){ float a = 71.0, b = 21.0; // Passing a and b and calling the subtract function by Reference subtract(&a, &b); printf("a = %f b = %f\n", a, b); return 0;}// Method definition to subtract two Numbers and store the answer in the first number passedvoid subtract(float *c, float *d){ *c = *c - *d; printf("c = %f d = %f\n", c, d);}

Output:

a = 50.0 b = 21.0 // Printed value in the subtract functiona = 50.0 b = 21.0 //. Printed value in the main function

NOTE: The values of the parameters passed changed in Call By Reference, that is, a became 50 and b became 21.

29.

Make a distinction between the following: #include and #include "file"?

Answer»

The key distinction between the two is the preprocessor's search location for the included FILE. The preprocessor looks in the same directory as the DIRECTIVE's file for #include "file" This METHOD is TYPICALLY used to include programmatically generated header files. The preprocessor, on the other hand, looks for #include <file> in pre-designated search directories by the compiler or the IDE (Integrated DEVELOPMENT Environment), which are not always in the same directory as the directive's file. This method is typically used to include standard library header files.

Previous Next