ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
int i = 5;
printf("%d ", i++);
printf("%d", ++i);
  1. A. 6 7
  2. B. 5 7
  3. C. 5 6
  4. D. 6 8

Correct answer: B. 5 7

i++ yields the old value (5) and then makes i 6. ++i increments first (to 7) and yields the new value. The two calls are separate statements, so the order is well defined.

More C Programming questions

Exams that ask this topic