ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int i = 3;
int r = MAX(i++, 2);
printf("%d %d", r, i);
  1. A. 3 4
  2. B. 4 4
  3. C. 3 5
  4. D. 4 5

Correct answer: D. 4 5

The macro expands to ((i++) > (2) ? (i++) : (2)). The condition reads 3 and increments i to 4 (the ?: has a sequence point after its condition), then the chosen branch i++ yields 4 and makes i 5. A function MAX would evaluate i++ once.

More C Programming questions

Exams that ask this topic