Question
Explain the concept of call by reference, with suitable code in C for each. Give advantage and disadvantage of call by reference
Answer :
Word Count : 643
__________ _______ _________ ______ ____.
________ ________ __________ _________ ______ _____ __________.
____ _________ _________ _____ _______ _____ __________ _______.
__________ _______ _______ ______ _________ _____ ______ __________ _______ ______ ________ ________.
______ _____ ___ ___ _____.
_________ _______ ____ __________ __________ ___ ________ ____ __________ ________.
________ _____ ________ _____ __________ _______ ____.
______ ___ _________ _________ ___ ____ _________ ____ ______ ________ ______.
_______ ________ _______ _______ ____ ____ _________ ______ ________ ____ ___ _________.
___ _____ ______ ________ ___ __________ _____ _____ _________ _______.
_______ __________ ___ ____ _________.
__________ ________ _____ ______ _______ ________ ________ _____ _______.
_____ _____ __________ _________ __________ __________ __________ ___ _______.
______ ____ _________ _____ ________ _____ _________ ____.
________ ______ __________ ______ ______ ______ ________ __________ ____ ________.
_________ ____ __________ ____ _______ _________ _____ ____ ________ ___ _____ _____.
___ _____ _______ _______ _______ __________ _________.
________ ________ _________ ___ _____ _______ _______ ______ ________.
_____ __________ ________ ________ _________ ________ _________ _______ ___ __________.
_____ __________ ________ _____ ______ _______ ________.
____ _____ _________ _________ _______ _________ ____ ______ ___ _______ _______ _____.
______ ________ ___ ___ _________ _____ ______ ____.
_______ ________ _______ _______ _____.
___ ____ __________ ________ __________ _____.
__________ _______ _________ ______ _______.
___ ____ ________ ________ ______ ______ _____ ______ _______ __________ _______ ___.
_____ ______ __________ ___ _____ _______ __________ ______.
_____ _______ _________ _____ _________.
_______ ___ _____ _________ _____.
__________ ____ _____ ___ _______.
___ ____ _____ __________ __________ __________ __________ __________ __________.
________ _________ __________ _________ ______ _______ _______ ____ ___.
________ ___ __________ __________ _______ _______.
_____ _________ __________ _______ ____ _______ _________ _________ ________ ___ ___.
_____ ____ _____ __________ ______ _______ _____ ______ ________ _________ ____ __________.
_______ ______ _________ _______ __________ ___ _________.
________ _____ ____ ________ ____ ______ ____ ________ __________ ______ ______.
___ ________ ________ ___ ________ ___ ___ __________ ___ ___.
_____ ____ ______ _____ ___ ______ __________ ____ _______.
_____ ______ ______ __________ _______ __________ ____ ____ _____ ___.
_______ ________ ______ _________ ______.
__________ _________ _______ _________ __________ ________.
__________ _______ _________ __________ ___.
_______ _____ _____ ___ __________ _________ ________ _________ ________ _________.
____ _______ ________ __________ ________ ____ ________ _______ ________ ___ ________ ___.
___ ___ __________ _________ ____ _______ _____ ___ ________ ______ ___ ___.
________ _____ __________ _______ _____ _____ ___ ___ ___ ________ _______.
______ ____ __________ ______ _________ _____ ______ ______ _______.
______ _______ _________ _______ _____ ______.
________ ____ __________ _________ _____ ______ ____ _______ _____ ________.
_______ ___ __________ __________ _______ _______ _______ __________ ___ ________ ___.
_________ ___ __________ _______ ______ _______.
__________ _________ _________ ________ _____ ______.
_________ ________ ________ ______ __________ ______ _________.
________ _______ _______ _________ __________ ___ _______.
_________ _________.
Skip in 10
In C programming, the concept of "call by reference" allows a function to modify the value of a variable in the calling code by passing its memory address instead of the actual value. This means that any changes made to the parameter within the function will affect the original variable outside the function.
To demonstrate this concept, let's consider an example using a swap function to interchange the values of two integers.
#include <stdio.h> void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } int main() { int x = 10; int y = 20; printf("Before swap: x = %d, y = %d\n", x, y); swap(&x, &y); // Passing the memory addresses of x and y printf("After swap: x = %d, y = %d\n", x, y); return 0; } Explanation:
- The
swapfunction takes two integer pointers (int *aandint *b) as parameters.
________ ________ __________ _________ ______ _____ __________.
____ _________ _________ _____ _______ _____ __________ _______.
__________ _______ _______ ______ _________ _____ ______ __________ _______ ______ ________ ________.
______ _____ ___ ___ _____.
_________ _______ ____ __________ __________ ___ ________ ____ __________ ________.
________ _____ ________ _____ __________ _______ ____.
______ ___ _________ _________ ___ ____ _________ ____ ______ ________ ______.
_______ ________ _______ _______ ____ ____ _________ ______ ________ ____ ___ _________.
___ _____ ______ ________ ___ __________ _____ _____ _________ _______.
_______ __________ ___ ____ _________.
__________ ________ _____ ______ _______ ________ ________ _____ _______.
_____ _____ __________ _________ __________ __________ __________ ___ _______.
______ ____ _________ _____ ________ _____ _________ ____.
________ ______ __________ ______ ______ ______ ________ __________ ____ ________.
_________ ____ __________ ____ _______ _________ _____ ____ ________ ___ _____ _____.
___ _____ _______ _______ _______ __________ _________.
________ ________ _________ ___ _____ _______ _______ ______ ________.
_____ __________ ________ ________ _________ ________ _________ _______ ___ __________.
_____ __________ ________ _____ ______ _______ ________.
____ _____ _________ _________ _______ _________ ____ ______ ___ _______ _______ _____.
______ ________ ___ ___ _________ _____ ______ ____.
_______ ________ _______ _______ _____.
___ ____ __________ ________ __________ _____.
__________ _______ _________ ______ _______.
___ ____ ________ ________ ______ ______ _____ ______ _______ __________ _______ ___.
_____ ______ __________ ___ _____ _______ __________ ______.
_____ _______ _________ _____ _________.
_______ ___ _____ _________ _____.
__________ ____ _____ ___ _______.
___ ____ _____ __________ __________ __________ __________ __________ __________.
________ _________ __________ _________ ______ _______ _______ ____ ___.
________ ___ __________ __________ _______ _______.
_____ _________ __________ _______ ____ _______ _________ _________ ________ ___ ___.
_____ ____ _____ __________ ______ _______ _____ ______ ________ _________ ____ __________.
_______ ______ _________ _______ __________ ___ _________.
________ _____ ____ ________ ____ ______ ____ ________ __________ ______ ______.
___ ________ ________ ___ ________ ___ ___ __________ ___ ___.
_____ ____ ______ _____ ___ ______ __________ ____ _______.
_____ ______ ______ __________ _______ __________ ____ ____ _____ ___.
_______ ________ ______ _________ ______.
__________ _________ _______ _________ __________ ________.
__________ _______ _________ __________ ___.
_______ _____ _____ ___ __________ _________ ________ _________ ________ _________.
____ _______ ________ __________ ________ ____ ________ _______ ________ ___ ________ ___.
___ ___ __________ _________ ____ _______ _____ ___ ________ ______ ___ ___.
________ _____ __________ _______ _____ _____ ___ ___ ___ ________ _______.
______ ____ __________ ______ _________ _____ ______ ______ _______.
______ _______ _________ _______ _____ ______.
________ ____ __________ _________ _____ ______ ____ _______ _____ ________.
_______ ___ __________ __________ _______ _______ _______ __________ ___ ________ ___.
_________ ___ __________ _______ ______ _______.
__________ _________ _________ ________ _____ ______.
_________ ________ ________ ______ __________ ______ _________.
________ _______ _______ _________ __________ ___ _______.
_________ _________.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.