y = f1(a, b, c);
is setting
y
to the output of the function
f1
Function f1 is defined from line 14 to line 19:
1 2 3 4 5 6
|
int f1(int x, const int& y, int& z)
{
x += y;
z += x;
return (x+y+z);
}
|
So the meaning of
y = f1(a, b, c);
is y = (x+y)+y+(z+(x+y)). Or y =(10+20)+20+(30+10+20). So y= 110
Maybe this will help:
Think of line 5:
y = f1(a, b, c);
as
y = f1(10, 20, 30);
.
What happens next is f1 is called with the three values 10, 20, and 30.
Inside f1 those values get new names: x, y, and z. So here x=10, y=20 and z=30. (Remember the &'s here in line 14, they will be important.)
x += y;
is short hand for
x = x + y
here x becomes 10+20.
z += x;
same sort of shorthand:
z = z + x;
so z becomes 30 + 30
lastly, the function returns x+y+z, AKA 30 + 20 + 60 = 110.
now we're back at line 6 setting
y = 110;
BUT the person who wrote the code was tricky, and returned data two different ways. The first way was directly though a return value, but the second way was by passing 2 of the variables by reference, that's what the &'s were for. That means that the value of those two variables gets returned to main and put back into their original variable names (
b and
c).
That is how to look at the program.
I'll leave it up to you to figure out what the final output will be.
Hope this helps!