ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
#define PRINT(x) printf(#x " = %d\n", x)
int main(void) {
    int value = 42;
    PRINT(value);
}
  1. A. 42 = 42
  2. B. "value" = 42
  3. C. Compilation error
  4. D. value = 42

Correct answer: D. value = 42

The # operator stringizes the macro argument as written in source, turning x into the literal string "value" (not its runtime value), so the expansion is printf("value" " = %d\n", value); adjacent string literals concatenate, producing "value = %d\n" with value substituted as 42.

More C Programming questions

Exams that ask this topic