ProgrammingHard

char b[5]; int n = snprintf(b, sizeof b, "%s", "abcdefgh"); printf("%s %d", b, n); What is printed?

  1. A. abcd 8
  2. B. abcde 8
  3. C. abcd 5
  4. D. abcd 9

Correct answer: A. abcd 8

The buffer holds four characters and a terminator, so b is abcd. snprintf returns the full length, 8.

More C Programming questions

Exams that ask this topic