Advertisements
Advertisements
Questions
Explain call by reference with a suitable example.
Explain call by reference with an example.
Explain
Advertisements
Solution
- In call by reference, when a function is invoked, the addresses of the actual arguments are passed to the formal parameters, meaning both refer to the same memory location.
- As a result, any change made to the formal parameters directly affects the values of the actual arguments.
- The variables modified inside the function are returned to the calling program with their updated values.
- For example:
void swap(int &a, int &b) { int temp = a; a = b; b = temp; }
shaalaa.com
Is there an error in this question or solution?
2018-2019 (December) CBCGS
