I am trying to explore the pointers in C, so pretty new to this subject. I came to know that best practice is to assign "NULL" when declaring a pointer. So in the below program I did the same:
#include <stdio.h>
int main() {
unsigned int *ip = NULL;
printf("Address stored in pointer: %x \n",ip); //gives 0
printf("Value stored at Address stored in pointer: %d \n",*ip); // gives "Segmentation fault (core dumped)"
return 0;
}
I am not able to understand clearly why this is happening. Shouldn't it output a value (NULL or something).
I am using centos 6.5 and gcc version 4.4.7.