Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern

What is printed? (C strings)

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

Correct answer: A. 9 10

strlen counts characters before the terminating '\0': 9. sizeof on a char array includes the terminator, so the array occupies 10 bytes. For a char * pointer, sizeof would give the pointer size instead.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic