← Quiz: String Handling in C: all 15 questions
Quiz: String Handling in C · Question 7 of 15
Why is strtol safer than atoi for converting text to a number?
Why is strtol safer than atoi for converting text to a number?
- A.strtol is faster
- B.strtol reports where conversion stopped, so you can detect invalid input; atoi just returns 0
- C.atoi cannot read negative numbers
- D.atoi only works on single digits
Answer & explanation
Correct answer: strtol reports where conversion stopped, so you can detect invalid input; atoi just returns 0
With atoi you cannot tell "0" from "abc"; strtol's end pointer tells you.
Can you get the rest right without peeking?
Take the timed Quiz: String Handling in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →