ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
#define PRINT(x) printf(#x " = %d\n", x)
int main(void) {
    int count = 5;
    PRINT(count);
}
  1. A. 5 = %d
  2. B. count = 5
  3. C. x = 5
  4. D. Compile-time error: #x inside a string is invalid

Correct answer: B. count = 5

# is the stringizing operator: #x converts the literal token count (whatever was textually passed as the argument) into the string literal "count", before any further substitution. The macro expands to printf("count" " = %d\n", count), and adjacent string literals "count" and " = %d\n" concatenate at compile time, printing count = 5.

More C Programming questions

Exams that ask this topic