ProgrammingModerateWipro · Capgemini pattern

What is printed?

What is printed?
char s[] = "hello";
char *p = s;
printf("%zu %zu %zu", strlen(s), sizeof(s), sizeof(p));   /* 64-bit system */
  1. A. 5 5 8
  2. B. 5 6 8
  3. C. 5 6 6
  4. D. 6 6 8

Correct answer: B. 5 6 8

strlen stops at the terminator (5). The array holds 5 characters plus '\0' (6 bytes). p is a pointer, so sizeof(p) is the pointer size, 8 on a 64-bit system – not the string length.

More C Programming questions

Exams that ask this topic