ProgrammingVery hardGATE CS

What is printed?

What is printed?
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main(void) {
    int i = 3, j = 5;
    int m = MAX(i++, j++);
    printf("%d %d %d", m, i, j);
    return 0;
}
  1. A. 5 4 7
  2. B. 5 4 6
  3. C. 6 4 6
  4. D. 6 4 7

Correct answer: D. 6 4 7

The macro expands to ((i++) > (j++) ? (i++) : (j++)). The condition 3 > 5 is false after i = 4 and j = 6; the ?: operator has a sequence point after its first operand, so the false branch evaluates j++ again, yielding 6 and leaving j = 7. Hence m = 6, i = 4, j = 7.

More C Programming questions

Exams that ask this topic