Null Pointers in C++

Pointer in C++ programming that is assigned NULL is called a null pointer. It is special type of pointer that does not point to any memory location.

Program NULL Pointer

Program

#include<iostream.h>
#include<conio.h>
void main()
{
   int *ptr = NULL; //assigning Null value to 'ptr'.
   cout<<"The value of NULL ptr is : "<<ptr; //printing 'ptr' value.
getch();
}
Output
The value of NULL ptr is : 0x00000000

Program Assigning Name to Pointer and Printing

Program

#include<iostream.h>
#include<conio.h>
void main()
{
char *po = "HiLaLs Afridi"; //assigning Name to Pointer 'po'.
cout<<"Your Name is: "<<po; //and printing.
getch();
}
Output
Your Name is: HiLaLs Afridi

Program Printing Pointer Array Names

Program

#include<iostream.h>
#include<conio.h>
void main()
{   //assigning elements'Name' to 'arr' Pointer Array.
 char *arr[4] = {"HiLaLs", "Khan", "Afridi", "PK"};
 for(int i = 0; i < 4; i++) //loop looping and
 {
 cout<<arr[i]<<endl; //printing Names.
 }
 getch();
}
Output
HiLaLs
Khan
Afridi
PK