ProgrammingModerate

char buf[16]; sprintf(buf, "%d-%d", 1, 22); printf("%zu", strlen(buf)); What is printed?

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

Correct answer: C. 4

sprintf writes "1-22" into buf, and strlen counts its four characters but not the terminator. 5 adds the '\0', and 3 forgets that 22 has two digits.

More C Programming questions

Exams that ask this topic