Multiple choice technology web technology

Consider the following code: int x, y, z; y = 1; z = 5; x = 0 - (++y) + z++; After execution of this, what will be the values of x, y and z?

  1. x = 4, y = 1, z = 5

  2. x = -7, y = 1, z = 5

  3. x = 4, y = 2, z = 6

  4. x = 3, y = 2, z = 6

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The prefix increment ++y makes y equal 2 immediately. The expression evaluates to 0 - 2 + z++ which is -2 + 5 = 3. Post-increment z++ increases z to 6 after evaluation. Thus, x becomes 3, y becomes 2, and z becomes 6.