Call-by-Ref-function in C++ .

In this session i have discussed call by ref function in C++ .


Before study the call by ref you must have knowladge of pointer so first study the pointer .

In call by ref , the original value can be changed or modified because we pass the reference or address . So the actual and formal both parameter contains the same address . So any value change inside the function it will reflect in both .


Example : Write a program that demonstrate the call by ref function .

  #include<iostream>
  using namespace std; 
  void display(int*x);
  int main()
  {  
       int x;
       x=10;
       cout<<" Value display from function\n ";
       display(&x);
       cout<<"\nValue display from x variable\n";
       cout<<"x : "<<x;
       return 0;
  }
  void display(int*x)
  {
      *x=*x+10;
      cout<<"x : "<<*x;
  }
  
  OUTPUT : Value display from function
           x : 20
           Value display from x variable
           x : 20
    


Welcome to AndroidATPoint.

back image                     next image