ProgrammingHardProduct-company MCQ pattern

What is printed?

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

Correct answer: D. 4 7 6

The macro expands to ((x++) > (y++) ? (x++) : (y++)). The test compares 3 > 5 (false) and leaves x = 4, y = 6; ?: has a sequence point after the test, then only the chosen branch y++ runs, giving z = 6 and y = 7. A function would have given 4 6 5.

More C Programming questions

Exams that ask this topic