NULL pointer in C

C++Server Side ProgrammingProgrammingC

A null pointer is a pointer which points nothing.

Some uses of the null pointer are:

a) To initialize a pointer variable when that pointer variable isn’t assigned any valid memory address yet.

b) To pass a null pointer to a function argument when we don’t want to pass any valid memory address.

c) To check for null pointer before accessing any pointer variable. So that, we can perform error handling in pointer related code e.g. dereference pointer variable only if it’s not NULL.

Algorithm

Begin.
   Declare a pointer p of the integer datatype.
      Initialize *p= NULL.
   Print “The value of pointer is”.
      Print the value of the pointer p.
End.


Example

 Live Demo

#include <stdio.h>
int main() {
   int *p= NULL;//initialize the pointer as null.
   printf("The value of pointer is %u",p);
   return 0;
}

Output

The value of pointer is 0.
raja
Published on 02-Apr-2019 13:23:57
Advertisements