← 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"?
- A.name is too small
- B.%s stops reading at the first space; use fgets to read a whole line
- C.scanf only reads 4 characters
- 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 →