🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: C Arrays and Strings: all 10 questions

Quiz: C Arrays and Strings · Question 10 of 10

Why does scanf("%s", name) read only "Asha" when the user types "Asha Rao"?

Why does scanf("%s", name) read only "Asha" when the user types "Asha Rao"?

  1. A.name is too small
  2. B.%s stops reading at the first space; use fgets to read a whole line
  3. C.scanf only reads 4 characters
  4. D.The space ends the program
Answer & explanation

Correct answer: %s stops reading at the first space; use fgets to read a whole line

%s reads one word. fgets(name, sizeof(name), stdin) reads the full line including spaces.

Can you get the rest right without peeking?

Take the timed Quiz: C Arrays and Strings quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →