ProgrammingHard

char a[10] = "hi"; printf("%zu", sizeof(a) - strlen(a) - 1); What is printed?

  1. A. 8
  2. B. 9
  3. C. 7
  4. D. 10

Correct answer: C. 7

sizeof counts all 10 bytes and strlen counts 2 characters. The terminator is one more byte, so 10 - 2 - 1 = 7 bytes stay unused after the string.

More C Programming questions

Exams that ask this topic