ProgrammingHardTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
#include <string.h>
int main(void) {
    char s[] = "hi\0there";
    printf("%zu %zu", sizeof s, strlen(s));
}
  1. A. 8 2
  2. B. 9 8
  3. C. 10 2
  4. D. 9 2

Correct answer: D. 9 2

The array holds 8 characters plus the terminating null, so sizeof s is 9. strlen stops at the first embedded null, giving 2.

More C Programming questions

Exams that ask this topic