what is call by value and call by reference in c++













call by value:





In call by value,do not change or modify original value because if we will change the value so that time of course change the value but in main() function do not except this value because old value is already store in stack memory.





For Ex.

coding:









#include<iostream>





using namespace std;

//call by value

void swap (int x, int y)

{

int temp;

temp = x;

x = y;

y = temp;

}





int main()

{

int x = 4,y = 7;

cout << "Before Swap:" << endl;

cout << "x=" << x << "\ty=" << y << endl;

swap (x, y);

cout << "After Swap:" << endl;

cout << "x=" << x << "\ty=" << y;

}









output :









call by reference:



