outp

My Cart

Explain the concept of call by reference, with suitable code in C for

Question


Explain the concept of call by reference, with suitable code in C for each. Give advantage and disadvantage of call by reference


Posted on : 2023-11-30 22:52:28 | Author : IGNOU Academy | View : 135

Click Here to Order on WhatsApp

Login or SignUp to View Answer / Comment or Ask Question.. Its Free

Word Count : 869

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








Degree : PG DIPLOMA PROGRAMMES
Course Name : POST GRADUATE DIPLOMA IN COMPUTER APPLICATIONS
Course Code : PGDCA_NEW
Subject Name : Programming in C and PYTHON
Subject Code : MCS 201
Year : 2023



IGNOU MCS 201 Solved Assignment 2023
Click Here to Order on WhatsApp

Call Now
Contact Us
Welcome to IGNOU Academy

Click to Contact Us

Call - 9199852182 Call - 9852900088 myabhasolutions@gmail.com WhatsApp - 9852900088
New to IGNOU Login to Get Every Update