Search code examples
carraysatoi

Printing atoi value of an uninitialised array


Simple question, below is my code. The number my compiler returns is 4219296. My question is: why? What is my code doing here?

#include <stdio.h>
char array[];

int main()
{

atoi(array);
printf("%d \n", array);


return 0;

}

Solution

  • The function atoi returns the converted value. This value needs to be stored. Here in the above program you are not storing the returned value. So there is no effect on the array variable.

    Printing the array in decimal format gives you the address of the array. The program shall print the same value even without the atoi function. To confirm try this:

    //...
    printf("%d \n", array);
    atoi(array);
    printf("%d \n", array);
    

    Output remains same.