ProgrammingHard

char w[16]; scanf("%15s", w); Why is the width 15 used?

  1. A. It reads exactly 15 characters, padding with spaces
  2. B. It leaves room for the terminator in a 16-byte buffer, so an overlong word cannot overflow it
  3. C. It stops at the first digit in the input
  4. D. It makes scanf faster by skipping newlines

Correct answer: B. It leaves room for the terminator in a 16-byte buffer, so an overlong word cannot overflow it

A width of 15 stores at most 15 characters plus the terminator in the 16-byte array. Longer words are cut off in the input stream.

More C Programming questions

Exams that ask this topic