🎙 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 13 of 15

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    char b[6];
    int n = snprintf(b, sizeof b, "%s", "placement");
    printf("%s %d\n", b, n);
    return 0;
}
  1. A.placement 9
  2. B.place 5
  3. C.place 9
  4. D.placem 6
Answer & explanation

Correct answer: place 9

snprintf writes at most 5 characters plus '\0' into the 6-byte buffer, but returns the full length it wanted to write (9).

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 →