LearnFrenzy
Sign in Take a free test

C Input / Output · Input/Output MCQ · Question 11

What does snprintf() return when output is truncated? Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 11 Back to Exercise

snprintf(buf, 8, "%s", "programming") – what does it return?

  • A 7, the characters written
  • B 11, the length the full output needed Correct
  • C -1, because it did not fit
  • D 8, the buffer size
Correct Answer: Option B

buf gets "program" (7 characters + '\0'), and the return value is the untruncated length, 11. A result ≥ the size means the output was cut.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links