English

Explain call by reference with a suitable example.

Advertisements

Questions

Explain call by reference with a suitable example.

Explain call by reference with an example.

Explain
Advertisements

Solution

  1. 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.
  2. As a result, any change made to the formal parameters directly affects the values of the actual arguments.
  3. The variables modified inside the function are returned to the calling program with their updated values.
  4. 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
Advertisements
Share
Notifications



      Forgot password?
Use app×