ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
#define SHOW(x) printf(#x " = %d", x)
int a = 3;
SHOW(a * 2 + 1);
  1. A. a * 2 + 1 = 7
  2. B. x = 7
  3. C. a * 2 + 1 = 9
  4. D. 7 = 7

Correct answer: A. a * 2 + 1 = 7

#x turns the argument's tokens into a string literal, "a * 2 + 1", which is joined to " = %d" by adjacent-literal concatenation. The second x is substituted as an expression, 3 * 2 + 1 = 7. '9' adds before multiplying.

More C Programming questions

Exams that ask this topic