Void and NULL pointer C progarm

This program demonstrates void pointer and null pointer in C. A pointer is a variable which stores the address of another variable. A null pointer does not point to anything and a void pointer can be used to point to a variable of any data type. In the program p is the null pointer and p1 is the void pointer, p is assigned with the value NULL and p1 is assigned with the address of the variable a, which is of integer data type. The statement (int *)p1; is to indicate that p1 refers to an integer data type.
 

Program


//C program to show the working of Void pointer and NULL pointer

#include<iostream.h> #include<conio.h> void main() { int *p=NULL,a; void *p1; cout<<"Enter the value for a"; cin>>a; p=&a; cout<<"Value of null pointer= "<<p; cout<<"Value of void pointer="<<(int *)p1; getch(); }

No comments: