Saturday, November 2, 2013

Null Pointer in C Language

,

A Pointer is variable which contains the address in memory of another variable.value of a pointer variable is a pointer to some other variable. There is one other value a pointer may have: it may be set to a null pointer. A null pointer is a special pointer value that is known not to point anywhere. What this means that no other valid pointer, to any other variable or array cell or anything else, will ever compare equal to a null pointer. A void pointer is declared like a normal pointer, using the void keyword as the pointer’s type.

To initialize a pointer to a null pointer (It is also possible to refer to the null pointer by using a constant 0), you might use code like

#include <stdio.h>
int *ip = NULL;

and to test it for a null pointer before inspecting the value pointed to, you might use code like

if(ip != NULL)
printf("%d\n", *ip);


Example :

#include <stdio.h>

int main()
{
 if(!NULL)
 {
  printf("I know preprocessor");
 }
 else
 {
  printf("I don't know preprocessor");
 }
 return 0;
}

0 comments to “Null Pointer in C Language”

Post a Comment