Multiple choice

What would be the output of the following?

main() { int y,x=5; y=++x - ++x; printf("%d%d",x,y); }

  1. 7 1

  2. 7 -1

  3. 7 0

  4. 5 1

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

Starting with x=5: first ++x makes x=6, then the second ++x makes x=7. So y=6-7=-1, and x=7. The printf outputs: 7 -1. The key is that both pre-increments happen before the subtraction, and both use the updated x value.