ProgrammingHardIBM · Deloitte pattern

Assume 32-bit int. What is printed?

Assume 32-bit int. What is printed?
int x = 5;
int y = x-- - --x;
printf("%d %d", x, y);
  1. A. 3 0, deterministically
  2. B. 3 2, deterministically
  3. C. Undefined behaviour: x is modified twice (by x-- and --x) with no sequence point separating them
  4. D. 4 1, deterministically

Correct answer: C. Undefined behaviour: x is modified twice (by x-- and --x) with no sequence point separating them

x-- - --x modifies x via two separate decrement side effects within the same expression (postfix and prefix), with no sequence point ordering them relative to each other — this is undefined behaviour in C, regardless of what any specific compiler's evaluation order happens to produce.

More C Programming questions

Exams that ask this topic