ProgrammingHardProduct company OA

What is printed?

What is printed?
printf("%zu %zu", sizeof("ab" "cd"), strlen("ab\0cd"));
  1. A. 6 2
  2. B. 5 2
  3. C. 5 5
  4. D. 6 5

Correct answer: B. 5 2

Adjacent string literals are merged into one, "abcd", which needs 5 bytes with its '\0'. strlen stops at the first '\0', which the escape puts after "ab", so it returns 2. '6' counts a terminator for each piece.

More C Programming questions

Exams that ask this topic