atoi Function : Convert String of Number into Integer



Atoi Function :

  • Atoi = A to I = Alphabet to Integer
  • Convert String of number into Integer

Syntax:

num = atoi(String);
num   - Integer Variable
String- String of Numbers

Example :

num = atoi("1947");
printf("%d",num);

Output :

1947

Significance :

  1. Can Convert any String of Number into Integer Value that can Perform the arithmetic Operations like integer
  2. Header File : stdlib.h

Ways of Using Atoi Function :

Way 1 : Passing Variable in Atoi Function  

// Variable marks is of Char Type

int num;
char marks[3] = "98";
num = atoi(marks);
printf("\nMarks : %d",num);

Way 2 : Passing Direct String in Atoi Function

int num;
num = atoi("98");
printf("\nMarks : %d",num);