← 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?
- A.It is faster
- B.It supports more format codes
- C.It takes the buffer size and never writes past the end of the buffer
- 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 →