🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: String Handling in C: all 15 questions

Quiz: String Handling in C · Question 5 of 15

Why is snprintf preferred over sprintf?

Why is snprintf preferred over sprintf?

  1. A.It is faster
  2. B.It supports more format codes
  3. C.It takes the buffer size and never writes past the end of the buffer
  4. D.It prints to the screen as well
Answer & explanation

Correct answer: It takes the buffer size and never writes past the end of the buffer

sprintf can overflow a small buffer; snprintf cuts the output to fit and returns the length it needed.

Can you get the rest right without peeking?

Take the timed Quiz: String Handling in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →