A NULL pointer assignment is a runtime error. It occurs due to various reasons:-- one is that ur program has tried to access an illegal memory location. Illegal location means either the location is in the operating systems address space or in the other processes memory space. In stdio.h NULL is defined as 0 So whenever your program tries to access 0th location the operating system kills your program with runtime assignment error because the 0th location is in the operating systems address space and operating system doesnt allow access to its address space by user program .
int* ptr = NULL; *ptr = 3;
There are many scenarios where you can see problems. But the key thing is, you did not allocate the memory for the pointer and you are trying to use the pointer.
See the following two statement
float *ptr = malloc( sizeof(*ptr) ); and float *ptr; ptr = malloc( sizeof(*ptr) );
In first case we allocate the memory to *ptr and in the second to ptr, why is such a difference.
What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?