ProgrammingModerateProduct-company MCQ pattern

What is printed?

What is printed?
char s[] = "abc\0def";
printf("%zu %zu", sizeof(s), strlen(s));
  1. A. 8 3
  2. B. 7 7
  3. C. 8 7
  4. D. 4 3

Correct answer: A. 8 3

The array keeps all 7 written characters (a b c \0 d e f) plus the automatic terminating '\0', so sizeof is 8. strlen stops at the first '\0', after abc, giving 3.

More C Programming questions

Exams that ask this topic