Question 3
Back to Exercise
Why was gets() removed from the C standard in C11?
- A It was too slow
- B It cannot limit input to the buffer size, so it always risks a buffer overflow Correct
- C It could not read spaces
- D It was replaced by scanf()
Correct Answer: Option B
gets(buf) is never told how big buf is, so a long line overflows it – a classic security hole. Use fgets(buf, sizeof buf, stdin).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!