ProgrammingModerateTCS NQT · Infosys pattern

What is printed?

What is printed?
#define DOUBLE(x) x + x
printf("%d", 10 / DOUBLE(5) * 2);
  1. A. 12
  2. B. 7
  3. C. 2
  4. D. 1

Correct answer: A. 12

Text substitution gives 10 / 5 + 5 * 2. With precedence that is (10 / 5) + (5 * 2) = 2 + 10 = 12, not 10 / 10 × 2 = 2. Always parenthesise the whole macro body and each parameter.

More C Programming questions

Exams that ask this topic