ProgrammingVery hardProduct company OA

What is printed?

What is printed?
int i = 1;
int arr[5] = {0};
int x = i + i++;
printf("%d", x);
  1. A. 3, since left operand reads first
  2. B. 2, since the increment happens first
  3. C. Compilation error
  4. D. Undefined behavior: i is both read for its value and modified (i++) with no sequence point separating them

Correct answer: D. Undefined behavior: i is both read for its value and modified (i++) with no sequence point separating them

i + i++ reads i's value twice (once directly, once via the post-increment's 'old value' read) and also modifies it once, all without a sequence point ordering these accesses relative to each other, which the C standard classifies as undefined behavior — not just 'implementation-defined' which would still have a guaranteed (if unspecified) answer per compiler.

More C Programming questions

Exams that ask this topic