Call by value:
-Here call by value refers as we call the function and pass the variable value instead of passing refrence of variable.
program:
#include < iostream>
using namespace std;
class Myclass
{
public:
void swap(int a,int b)
{
int t=a;
a=b;
b=t;
cout<<"After swapping numbers"<< a<<" "<< b<< endl;
}
};
int main()
{
Myclass obj;
int i=10,j=20;
cout<<"Before function calling"<< endl;
cout<<"i and j is: "<< i<<"t"<< 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 swapping numbers 20 10
After function calling
i and j is: 10 20