Advertisements
Advertisements
प्रश्न
Explain call by reference with a suitable example.
Explain call by reference with an example.
स्पष्ट करा
Advertisements
उत्तर
- 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
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2018-2019 (December) CBCGS
