ProgrammingHard

char buf[3]; int n = snprintf(buf, 3, "%s", "hello"); printf("%d", n); What is printed?

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

Correct answer: D. 5

snprintf returns the length the full output would have had, 5, even though only 'he' fits in the 3-byte buffer.

More C Programming questions

Exams that ask this topic