ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
int a = 10;
int b = a++ + a++;
printf("%d", a);
  1. A. 11
  2. B. 12
  3. C. Undefined behaviour: a is modified twice without an intervening sequence point
  4. D. 10

Correct answer: C. Undefined behaviour: a is modified twice without an intervening sequence point

a++ + a++ contains two unsequenced modifications of the same variable a within one full expression, which is undefined behaviour regardless of what value a (or the sum) appears to end up with on any particular compiler.

More C Programming questions

Exams that ask this topic