ProgrammingHardTCS NQT · Infosys

What is printed? Assume the array has space for 5 characters.

What is printed? Assume the array has space for 5 characters.
#include <stdio.h>
int main(void) {
    char s[5] = "abcd";
    printf("%zu", sizeof s);
}
  1. A. 5
  2. B. 4
  3. C. 6
  4. D. 8

Correct answer: A. 5

The array is declared with 5 elements, so sizeof s is 5 and the string fills four of them with a terminating null.

More C Programming questions

Exams that ask this topic