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;
}