+ 2
Why does the code result in 7?
2 odpowiedzi
+ 2
Zacq
x = 0
y = 5
z = x++ + ( ++x + y--)
Here, x++ makes use the 0 value of x then increases so now,
z = 0 + (++x + y--)
But, x = 1.
Then we have ++x, which makes our x=2 then uses its value.
z = 0 + (2 + y--)
Then we have y--, which uses y's value then decreases.
So,
z = 0 + ( 2 + 5)
z = 7
At the end,
x = 2, y=4, z=7
+ 4
Mustafa K. Thanks! makes sense, so increment(decrement) applies from left to right and carries the changes forward.
My mistake was to take the same line as just one block