ProgrammingVery hardTCS NQT · Infosys

#define MAX(a,b) ((a)>(b)?(a):(b)). With int i = 7; int m = MAX(i++, 5); what are m and i afterwards?

  1. A. m = 7, i = 8
  2. B. m = 8, i = 9
  3. C. m = 8, i = 8
  4. D. m = 7, i = 9

Correct answer: B. m = 8, i = 9

The condition evaluates i++ once (7 > 5, and i becomes 8). The selected branch evaluates i++ again, which yields 8 and makes i 9. A side-effecting macro argument can run more than once.

More C Programming questions

Exams that ask this topic