Multiple choice technology programming languages

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 = 2, z = 6

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

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

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

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

Pre-increment (++y) increments before use: y becomes 2. Post-increment (z++) uses old value then increments: z remains 5 for the expression. x = 0 - 2 + 5 = 3. After expression, z increments to 6. Final: x=3, y=2, z=6.