top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is a null pointer?

0 votes
217 views
What is a null pointer?
posted Jul 22, 2014 by anonymous

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

1 Answer

0 votes

Pointer that is assigned NULL is called a null pointer or we can say A null pointer is a special pointer that doesn't point to anything. It is a good practice to assign a NULL value to a pointer variable in case you do not have exact address to be assigned.

main ()
{
   int  *ptr = NULL; // ptr is a null pointer here
   printf("The value of ptr is : %x\n", ptr  );
}

Use Case To check for a null pointer one can use if statement as follows:

if(ptr)     /* succeeds if p is not null */
if(!ptr)    /* succeeds if p is null */ 

Read more at: http://tech.queryhome.com/45285/c-programming-pointers-basic

answer Jul 22, 2014 by Salil Agrawal
...