Call-By-Value / Call-By-Reference Example



//	Call-by-Value/Call-by-Reference Example

#include 

using namespace std;

int main()
{
	int byValue(int x);
	int byRef(int &x);
	
	int a, b, c;
	
	cout << "CALL-BY-VALUE / CALL-BY-REFERENCE EXAMPLE\n\n";

	a = 10;
	c = a;
	b = byValue(a);
	cout << "Call-By-Value --\n";
	cout << "\t a Before: " << c << '\n';
	cout << "\t a After:  " << a << '\n';
	cout << "\t b After:  " << b << "\n\n";

	a = 10;
	c = a;
	b = byRef(a);
	cout << "Call-By-Reference --\n";
	cout << "\t a Before: " << c << '\n';
	cout << "\t a After:  " << a << '\n';
	cout << "\t b After:  " << b << "\n\n";

	return 0;
}

int byValue(int x)
{
	x = x + 10;
	return x;
}

int byRef(int &x)
{
	x = x + 10;
	return x;
}