storing an integral value in a pointer variable while declaration
Posted
by benjamin button
on Stack Overflow
See other posts from Stack Overflow
or by benjamin button
Published on 2010-03-19T12:23:56Z
Indexed on
2010/03/19
12:31 UTC
Read the original article
Hit count: 257
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!
© Stack Overflow or respective owner