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 */
Thats agreed... whats the result in the following case. int *ptr= NULL; printf("%d",ptr); int *ptr; *ptr = NULL; printf("%d",ptr);
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 !)