ProgrammingHardWipro · Cognizant pattern

What is printed?

What is printed?
#define CONCAT(a, b) a##b
int xy = 42;
printf("%d", CONCAT(x, y));
  1. A. 42
  2. B. Compile-time error: a##b is invalid syntax
  3. C. 0
  4. D. x times y, computed at compile time

Correct answer: A. 42

## is the token-pasting operator: CONCAT(x, y) literally glues the tokens x and y together into the single identifier xy at preprocessing time, which then refers to the existing variable xy, printing 42.

More C Programming questions

Exams that ask this topic