ProgrammingHardTCS NQT · Wipro

What is printed?

What is printed?
#define MUL(a, b) a * b
#define ADD(a, b) a + b
printf("%d", MUL(ADD(1, 2), ADD(3, 4)));
  1. A. 21
  2. B. 11
  3. C. 15
  4. D. 13

Correct answer: B. 11

Macros paste text with no parentheses: the line becomes 1 + 2 * 3 + 4, and * binds first, giving 1 + 6 + 4 = 11. 21 is the intended (1+2)*(3+4); 13 and 15 come from parenthesising only one of the two arguments.

More C Programming questions

Exams that ask this topic