Void Pointers In C With examples

C Void Pointer Definition

A void pointer in c is called a generic pointer, it has no associated data type. It can store the address of any type of object and it can be type-casted to any types.

A void pointer declaration is similar to the normal pointer, but the difference is that instead of data types we use the void keyword.

The size of a void pointer is similar to the size of the character pointer.

The size of the pointers depending on the platform and it can be 2bytes, 4bytes or 8bytes …etc.


Syntax to declare void pointer


 void * pointer-name;

Example :



Output:

 Integer variable is = 6
 Float variable is = 4.200000

Example 2:

On a 64bit machine



Output:

 size of void pointer = 8
 size of integer pointer = 8
 size of character pointer = 8
 size of float pointer = 8