ProgrammingHardTCS NQT · Infosys

char buf[5] = "abcd"; printf("%zu", sizeof(buf) - strlen(buf)); What is printed?

  1. A. 5
  2. B. 4
  3. C. 0
  4. D. 1

Correct answer: D. 1

sizeof(buf) is 5 and strlen(buf) is 4, so the difference is 1. The terminator is included in the array size but not in strlen.

More C Programming questions

Exams that ask this topic