atoi()

 Hey all, 

Before checking this post, just go through this one Click Here.




#include <stdio.h>
#include <stdlib.h>
 
int main()
{
   char str[10] = "4294967295";
   char str1[10] = "2147483647";
   int var = atoi(str);
   long int var1 = atoi(str);

   printf("str [%s] var d [%d] u[%u] var1 ld[%ld]\n ", str, var, var, var1);
   var = atoi(str1);
   var1 = atoi(str1);
   printf("str1 [%s] var d [%d] u[%u] ld[%ld]\n ", str1, var, var, var1);

   return 0;
}


Output:

1
2
3
str [4294967295] var d [2147483647] u[2147483647] var1 ld[2147483647]
 str1 [21474836474294967295] var d [2147483647] u[2147483647] ld[2147483647]
 


Here, even if the string and var1 capable of  holding 32-bit value, atoi converts and returns only 31-bit value. This predominantly concludes atoi is only for 31-bit data type. 




Comments