ProgrammingVery hard

char a[20], b[20]; /* stdin: "hi there\nnext\n" */ scanf("%s", a); fgets(b, sizeof b, stdin); What is stored in b?

  1. A. a space, then 'there', then a newline
  2. B. 'there' then a newline
  3. C. 'hi there' then a newline
  4. D. 'next' then a newline

Correct answer: A. a space, then 'there', then a newline

scanf with %s stops at the first whitespace, leaving the space that follows 'hi' in the input. fgets then reads from that space up to the newline.

More C Programming questions

Exams that ask this topic