ProgrammingHardTCS NQT · Infosys pattern

What is printed?

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

Correct answer: A. apple = 10

The # operator stringizes the macro argument as written in source, turning the identifier apple into the string literal "apple", so the call expands to printf("apple" " = %d\n", apple), printing "apple = 10".

More C Programming questions

Exams that ask this topic