What is Void Pointers in C :

  1. In C General Purpose Pointer is Called as void Pointer.
  2. It does not have any data type associated with it
  3. It can store address of any type of variable
  4. A void pointer is a C convention for a raw address.
  5. The compiler has no idea what type of object a void Pointer “really points to.” ?

Declaration :

void * pointer_name ;

Live Example :

void *ptr;    // ptr is declared as Void pointer
char cnum;
int inum;
float fnum;
ptr = &cnum;  // ptr has address of character data
ptr = &inum;  // ptr has address of integer data
ptr = &fnum;  // ptr has address of float data

Explanation :

void *ptr;
  • Void pointer declaration is shown above.
  • We have declared 3 variables of integer,character and float type.
  • When we assign address of integer to the void pointer, pointer will become Integer Pointer.
  • When we assign address of Character Data type to void pointer it will become Character Pointer.
  • Similarly we can assign address of any data type to the void pointer.
  • It is capable of storing address of any data type