ProgrammingModerate

char name[10]; /* input: a long name */ scanf("%9s", name); What is the most characters stored before the terminator?

  1. A. 10
  2. B. 8
  3. C. No limit: %s keeps reading until whitespace
  4. D. 9

Correct answer: D. 9

The field width caps the conversion at 9 characters, and scanf then stores the '\0' at index 9, exactly filling the 10-byte array. 10 forgets the terminator needs a byte, and 8 wrongly assumes the width already includes it.

More C Programming questions

Exams that ask this topic