ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
#define STR(x) #x
#define CAT(a, b) a##b
int xy = 7;
printf("%s %d", STR(x+y), CAT(x, y));
  1. A. x+y xy
  2. B. Compilation error
  3. C. x+y 7
  4. D. 7 7

Correct answer: C. x+y 7

# turns the macro argument into a string literal, so STR(x+y) is "x+y". ## pastes tokens, so CAT(x, y) becomes the identifier xy, whose value is 7. No variables x or y are needed.

More C Programming questions

Exams that ask this topic