C Programming · Question 28 · Hard

What will be the output of the following C program?

#include <stdio.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
    int i = 3, j = 2;
    int m = MAX(i++, j);
    printf("%d %d", m, i);
    return 0;
}
  1. 4 4
  2. 4 5
  3. 3 5
  4. 3 4
Answer and explanation

Answer: B. 4 5

Explanation: The macro expands to ((i++) > (j) ? (i++) : (j)). The test compares 3 > 2 and leaves i as 4; the true branch then evaluates i++ again, giving m = 4 and leaving i as 5.

Previous: What will be the output of the following C program? · Next: What will be the output of the following C program?

Practise c programming

Try a fresh set of c programming questions with an explanation after every answer, free and without signing up: C Programming practice. Or sit a full placement mock test.

More c programming questions

More technical & programming practice

Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge