Question
Explain the concept of call by reference, with suitable code in C for each. Give advantage and disadvantage of call by reference
In programming, *Call by Reference* is a method of passing arguments to a function. Instead of passing a copy of the variable (as in call by value), the address (reference) of the variable is passed. This allows the function to modify the actual value of the variable in the caller's scope.
### Concept of Call by Reference
When a function is called using *call by reference*, the function receives the reference (memory address) of the arguments, which means any changes made to the parameter within the function will directly affect the actual argument in the calling function. This is different from *call by value*, where the function only works with a copy of the argument, and modifications within the function do not affect the original variable.
In C, call by reference is implemented using pointers. A pointer is a variable that stores the address of another variable, allowing direct manipulation of the variable's value.
### Call by Reference in C
In C, to implement call by reference, we pass the address of the variable to the function using pointers. Here is an example:
```c
#include <stdio.h>
void add(int *a, int *b) {
*a = *a + *b; // Modify the value of 'a' directly
}
int main() {
int x = 5, y = 10;
printf("Before calling function: x = %d, y = %d\n", x, y);
add(&x, &y); // Passing the addresses of x and y
printf("After calling function: x = %d, y = %d\n", x, y);
return 0;
}
```
### Explanation:
- The function `add()` takes two pointer arguments (`int *a, int *b`).
- Inside ____________ ________ ___ ___________ _____________ __ __ ____________ ________ ____ _______ ____.
______ ____ ______ _________ _______ _____________.
____________ ____________ ____________ ___________ _____________ ________ __ ______ ______.
____________ _______ ___ ___________ _________ _______ ____ _________ _____ __ ________ ______ _______ __ ______.
__ ____________ _______ _____ __________ ________ ____________ ________ __ _______ ___________ ___________ ____________ _________.
___________ ____________ ________ ________ ______ __.
___ _______ _______ ____________ ____________ ______ _____________ ___ ____ __________ __________ ___________.
_____________ ___________ __________ _____ _________ ___________ ___________ ____________ ___ __________ _____ __.
___ ___________ ___ ________ ________ __________.
___________ ______ _________ __ __________ ____ __ _____________.
____________ _____ _________ _______ _____________ _____ ___________ __ _________ ___________.
_______ ____________ ________ ___ ___ __ ___________ ____________ _____.
__ ______ _____________ _______ ________ _________.
__________ ____________ _____ ______ ______ ___ __________ _____________ ______.
___ ________ ____ _______ ___________ __ ___ ______ _____________ _______ ________.
_______ _________ ______ __ ___ ________.
___________ __ ________ __ __________ ____ _____ ___ ____________ ___________ ________ __ _________.
________ _____________ ______ ___ ____________ ________ _______ ______ ____ _____ _________ ___________ _____________ ____.
__________ __ ______ _____________ ____ _____ _________ ______ ___ __ _____________ __ ____.
___________ ____________ ______ _____________ _______ ____ _________.
_________ ____ ____ _________ ______ ___________ ____.
__ ________ _____________ __________ ______ ______ ______ _____.
____ _______ ___ _________ _______ _____________ ________ ____________ ______ _____ _______ ___.
____________ __ _____________ ________ __________ ________ ____ _______ _____________ ___ ____________ ______ _______ ___________.
___ ____ _____________ ___ ___________ ___.
____________ _______ ____________ ____________ ____ _______ __ __________ ____ _____________ _____ ________ ________ _______ _____.
__ ________ _________ ________ _____________ ____ __________ _____ ____ ___ __________ _______ __________.
______ __________ ______ _________ __________ ____ ____ _______ ____ __ _______ ___________ ___ _______.
_____ __________ ___________ ______ __________ _________ ____________ ____.
_____ ______ ___ __ ____ ____________ __________ ____________ ______ ____ ______ ___________ ______ ______ ______.
_________ ________ __ _________ ___ _____ ___________ _________ ______.
____ _____ __________ ______ _______ ___ _____________ __ _________.
______ ________ _______ ________ __________ _____ ___________ __ ___ ____ _______ __ ___ _______ _________.
_____________ ____________ ____________ _______ _____ ___________ ______.
____________ ___ ______ _____ ____ ____________ _________.
___ __ _____________ ___________ _______ _________ _______ ________ _____ ___.
_________ ___ ________ ______ ___ __________ _________ ______ __________ ______ _______ _____________.
__ ________ ____ ________ _______ __ _____________ _____ _____________ ____ _______ ___ ______.
__ _____________ _______ ______ ________ __________ _____________ ____________ ______.
___________ __________ _____________ ____________ ___ _________ ______ __ ____________.
_________ _____________ __________ ___________ _____________ ____________ __________ ________ __________ ___________ ______ _____.
__________ ____________ __ ____________ ___________ ___________ ____________ ____________ _____________ ________ _____________ ____ ________ ____.
_____________ __________ _____ _____________ __ _____ __________ ____________ _____________ ___.
__________ _______ __ __ ___________ ________ ___ __ _____________ _____________ ________ ____ _____ _____________ ___________.
_______ ____ ___________ ______ _____ ___________ _______ ______ ______ __ _______ __________ ________ ________.
_________ ___ ______ ________ __ ___________ __________.
___________ ____ ____________ ______ ______ ____________ ____ __________.
___ ____ ________ ______ ______ ___ ___________ __ ___ ____ __________ ___________ ____________.
_____ _____ ____________ ____ _____ ____________ _____.
___ ________ _________ ____________ _______ ______ ___ _____________.
___ _________ _____ ___________ ____ ___ ________ ___________ ___________ _______ ____________ _____ ____.
_______ ____________ _____ _____ __________ __ __________ ________ _______ _____ __.
_____________ ________ __ __________ ______ _____________ ________ ________ ______ ____ ______ __________ ____ _________.
__________ ______ ___ ____________ _______ ___ __.
____ ____ ______ _____________ ____ ____________ _________ ___ ______ ______ __________ ___________.
________ _______ __________ _______ ___.
Click Here to Order Full Assignment on WhatsApp
Lists
Write Python code to perform the following :
a. Reading data from a file
b. Creating a file and add content to it
Compare any two of the following (give suitable C code for each) :
a. Break and Continue Statement
b. Structure and Union
Compare overloading and overriding in Python. Give suitable example code for each in Python.
Co-routines and threads
What is the utility of map( ) function do ? Write a program in Python to print the square of the numbers present in the list, by using map( ) function.
Briefly discuss the relation between pointers and arrays, giving suitable example. Write a program in C, to print transpose of a 2D matrix entered by a user. Also give comments.
Click to Contact Us
Call - 9199852182 Call - 9852900088 myabhasolutions@gmail.com WhatsApp - 9852900088