C++ Call by Reference
In call by reference function, the action is performed over the actual value pass in the parameter. At the time of function call, we pass the address or reference of value. So that in the call by reference the actual value inside and outside the function of the program got affected.
Example
#include<iostream>
using namespace std;
void swap(int *,int *);
int main()
{
int a=5,b=10;
cout<<"Before swapping\nValue of a is :"<<a<<"\nValue of b is :"<<b;
swap(&a,&b);
cout<<"\nOutside function after swapping\nValue of a is
:"<<a<<"\nValue of b is "<<b;
return 0;
}
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
cout<<"\nValue inside function after swapping\nValue of a is
:"<<*a<<"\nValue of b is :"<<*b;
}
Before swapping Value of a is : 5 Value of b is: 10 Value inside function after swapping Value of a is :10 Value of b is :5 Outside function after swapping Value of a is : 10 Value of b is: 5