ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
#define TWICE(x) (2 * (x))
#define FOUR_TIMES(x) TWICE(TWICE(x))
printf("%d", FOUR_TIMES(3));
  1. A. 12
  2. B. 9
  3. C. 6
  4. D. 24

Correct answer: A. 12

FOUR_TIMES(3) expands to TWICE(TWICE(3)), inner TWICE(3) becomes (2*(3))=6, then outer TWICE((2*(3))) becomes (2*((2*(3)))) = 2*6 = 12.

More C Programming questions

Exams that ask this topic