ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

What is printed?
int a = 5;
int b = a++ + ++a;
printf("%d %d", a, b);
  1. A. Undefined behaviour: a is modified by both a++ and ++a within the same expression with no sequencing between them
  2. B. 12 7
  3. C. 11 12
  4. D. 7 12

Correct answer: A. Undefined behaviour: a is modified by both a++ and ++a within the same expression with no sequencing between them

a++ and ++a both modify the same object a within the single expression `a++ + ++a`, and + does not sequence its operands — two unsequenced modifications of the same scalar is undefined behaviour, so neither a nor b has a single portably guaranteed value.

More C Programming questions

Exams that ask this topic