Question 11
Back to Exercise
Why is strtol() preferred over atoi() for user input?
- A atoi is slower
- B atoi only handles positive numbers
- C strtol works only on hex
- D atoi cannot report invalid input or overflow; strtol gives the end position and sets errno to ERANGE Correct
Correct Answer: Option D
atoi("abc") returns 0 with no way to tell it from "0", and an out-of-range value is undefined behaviour.
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!