I was wondering why the output of the following code is:
x = 1
y = 2
z = 3
x = 2 (understand here up)
y = 2 (Why isn't it 3)
z = 5 (Why isn't it 4)
x = 1
y = 2
z = 3
x = 2 (understand here up)
y = 2 (Why isn't it 3)
z = 5 (Why isn't it 4)
Code:
int F(int& x, int y)
{
x = x+1;
y = y +1;
return x + y;
}
int main()
{
int x, y, z;
x = 1, y = 2, z = 3;
std::cout << "x=" << x << '\n'
<< "y=" << y << '\n'
<< "z=" << z << '\n';
z = F(x,y);
std::cout << "x=" << x << '\n'
<< "y=" << y << '\n'
<< "z=" << z << '\n';
return 0;
}
Comment