ProgrammingModerateAccenture · Cognizant pattern

What is printed?

What is printed?
char s[] = "placement";
printf("%zu %zu", sizeof(s), strlen(s));
  1. A. 10 9
  2. B. 9 9
  3. C. 10 10
  4. D. 9 10

Correct answer: A. 10 9

The array holds 9 letters plus the terminating '\0', so sizeof(s) = 10. strlen counts characters before the '\0', giving 9.

More C Programming questions

Exams that ask this topic