ProgrammingVery hardAccenture · C · Advanced

What is printed?

What is printed?
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
    int i = 3, j = 1;
    int m = MAX(i++, j++);
    printf("%d %d %d", m, i, j);
    return 0;
}
  1. A. 3 4 2
  2. B. 4 5 2
  3. C. 4 4 2
  4. D. 3 5 2

Correct answer: B. 4 5 2

The expansion evaluates i++ in the condition (3 > 1, sequence point) and again in the chosen branch, so m = 4, i = 5; j++ runs once, so j = 2.

More C Programming questions

Exams that ask this topic