ProgrammingModerateTCS NQT · Accenture

What is printed by sizeof?

What is printed by sizeof?
#include <stdio.h>
int main(void) {
    char t[] = "a\0b\0c";
    printf("%zu", sizeof t);
}
  1. A. 3
  2. B. 4
  3. C. 5
  4. D. 6

Correct answer: D. 6

The array holds five characters, the embedded nulls included, plus the terminating null, so sizeof t = 6. strlen would stop at the first null and give 1.

More C Programming questions

Exams that ask this topic