top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C: What is a null pointer assignment error?

+4 votes
984 views
C: What is a null pointer assignment error?
posted Dec 4, 2013 by Deepak Raijada

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

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;
answer Dec 4, 2013 by Alok Kumar
0 votes

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.

answer Dec 4, 2013 by Meenal Mishra
Similar Questions
+3 votes

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.

0 votes

What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

...