Quote:Original post by Blckknight118
[
b is the third parameter. So does that mean that b is passing the value 9 to y.
No. 'b' is passed to the third parameter. The third parameter in foo() is 'z' (not 'y') so 'z' gets a copy of what was in 'b'.
Quote:I understand that, but the last cout that has the whole function makes no sense.
The last cout, the one that is in main takes what foo returns. To save time,
foo returns x, x within foo is the first parameter, and in the call in main is y (which is 4) is passed as the first parameter.
So foo's 'x' becomes 4, foo returns it's x so foo returns a value of 4. cout is taking the value that foo is returning (4) and doing what it does.
This can only happen AFTER all the functions called on the line
std::cout << foo( y, a, b ) << std::endl;
have been resolved.
So the process to executing the above line is:
1. Call foo (with y,a and b).
2. As a result of being called foo outputs the two values.
3. foo returns a value, in this case 4 because that was the contents of 'x'.
4. The result is now used in place of the function call, like this: std::cout << 4 << std::endl;
5. So the std::cout is called with 4 (and then a new line). So it outputs 4.