# Thread: Easy question re: Calling by Value vs Reference

1. ## Easy question re: Calling by Value vs Reference

Hi All, thanks in advance for any help....

I'm having a hard time seeing the difference between calling by value vs calling by reference. In the following example, I receive the same result when the program is executed.

I'm wondering if anyone can provide an example where using the call by reference would produce a different result, or at least some type of explanation on the difference?

Here's the example:
________________

int tripCBV(int);
int tripCBR(int &);

int main()
{
int number, result1, result2;

cout << "enter a number to be tripled: ";
cin >> number;

result1 = tripCBV(number);
result2 = tripCBR(number);

cout << "CBV result is " << result1 << endl;
cout << "CBV result is " << result2 << endl;

return 0;
}

int tripCBV(int x)
{
int y;

y = 3 * x;
return y;
}

int tripCBR(int &x)
{
int y;

y = 3 * x;
return y;
}

2. When you pass a variable by value to a function a copy of that variable is made. You can do anything you want to that copy of the value, and it will not change the value of the original variable. When you pass by reference a copy of the variable is not made, instead whenever you change the value of the reference the value of the original variable is also changed.

3. Got it... thank you!