The atoi() is a c library function used to convert a numeric string to his integer value.
Steps to create own atoi().
The atoi() only convert a numeric string to their integer value, so check the validity of the string. If any non-numeric character comes, the conversion will be stopped.
Subtract 48 (ASCII value of 0) from the string character to get the actual value and perform some arithmetical operation.
for example,
If the numeric string is “124”, we know that ASCII value of ‘1’, ‘2, and ‘4’ is 49, 50 and 52 respectively. So if we subtract 48 from these numeric characters we will get the actual numeric value 1,2 and 4.
Output: -1230
need an explanation for this answer? contact us directly to get an explanation for this answer