ProgrammingVery hardProduct company OA

What is printed?

What is printed?
#define S(x) #x
printf("%zu %zu", strlen(S("hi")), sizeof(S(ab)));
  1. A. 4 2
  2. B. 2 3
  3. C. 2 2
  4. D. 4 3

Correct answer: D. 4 3

Stringising an argument that is itself a string literal keeps its quotes, escaped: S("hi") becomes "\"hi\"", the 4 characters "hi" including both quote marks. S(ab) becomes "ab", whose sizeof is 3 including the '\0'.

More C Programming questions

Exams that ask this topic