ProgrammingHardHCL · Tech Mahindra pattern

What is printed?

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

Correct answer: B. value = 42

The # operator (stringizing) converts the macro argument's literal TEXT into a string literal, so #x becomes "value" (the identifier's spelling, not its runtime value). The expansion is printf("value" " = %d\n", value), and adjacent string literals concatenate: "value = %d\n" with value substituted as 42.

More C Programming questions

Exams that ask this topic