Are these two statements same?

amitnvaidya's Avatar, Join Date: Oct 2009
Newbie Member
int *ptr = "NULL"; // Here is a statement

int *ptr; // Here is a set of two statements
*ptr = "NULL";

/*
when
you print the first
it gives 0
and second if you print
it gives linking error
why so
*/
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
NULL should be NULL and not "NULL" as "NULL" one is a string literal
amitnvaidya's Avatar, Join Date: Oct 2009
Newbie Member
Thats agreed... whats the result in the following case.

int *ptr= NULL;
printf("%d",ptr);



int *ptr;
*ptr = NULL;
printf("%d",ptr);
SaswatPadhi's Avatar, Join Date: May 2009
~ Б0ЯИ Τ0 С0δЭ ~
In the first case, you assign NULL to the pointer (the address), NOT to the value pointed by it.
In the second case, you assign NULL to the value pointed by the pointer.
So, the cases are not equivalent.

These are equivalent :

int *ptr = NULL;
printf("%d", ptr);

int *ptr;
ptr = NULL;
printf("%d",ptr);

And should have equal behaviour on compilation. (Try them !)