storing an integral value in a pointer variable while declaration
- by benjamin button
int main()
{
int *d=0;
printf("%d\n",*d);
return 0;
}
this works fine.
>cc legal.c
> ./a.out
0
if i change the statement int *d=0; to int *d=1;
i see the error.
cc: "legal.c", line 6: error 1522: Cannot initialize a pointer with an integer constant other than zero.
so its obvious that it will allow only zero.i want to know what happens inside the memory when we do this int *d=0 which is making it valid syntax.
I am just asking this out of curiosity!