🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.strtol is faster
  2. B.strtol reports where conversion stopped, so you can detect invalid input; atoi just returns 0
  3. C.atoi cannot read negative numbers
  4. 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 →