Call by reference:
-Here call by reference means we call a function and pass variable reference instead of variable value.
-Pointer are used in such kind of calling.
program:
#include < iostream>
using namespace std;
class Myclass
{
public:
void swap(int *a,int *b)
{
int t=*a;
*a=*b;
*b=t;
}
};
int main()
{
Myclass obj;
int i=10,j=20;
cout<<"Before function calling"<< endl;
cout<<"i and j is: "<< i<<" "<< j<< endl;
obj.swap(&i,&j);
cout<<"After function calling"<< endl;
cout<<"i and j is: "<< i<<" "<< j;
return 0;
}
Before function calling
i and j is 10 20
After function calling
i and j is 20 10