ProgrammingHard

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

  1. A. 5 1234
  2. B. 5 123
  3. C. 4 123
  4. D. 3 123

Correct answer: B. 5 123

The full text 12345 has five characters, so snprintf returns 5. The buffer keeps the first three digits and the terminator.

More C Programming questions

Exams that ask this topic