Google Add

Search

Void Pointer and It's Usage


Void Pointer


In simple terms void pointer is a General Purpose Pointer or Generic Pointer. Void indicates the absence of type.


** void pointer store the address of any type of variable.

** void pointer is declared with keyword void.

** It is very useful when programmer is not sure about the input data.


Let's learn through example


float *num; // Declare pointer of type float

int number; // Declare int

num = &number; //Gives compilation error


void *num; // num is declared as void pointer
int number;

num = &number; // Works


float a;

num = &a; // Stores the address of float data




** Pointer Arithmetic cannot be performed using void pointer.


void *val;

int num;

val = #

val++; // Invalid, it won't work

No comments:

Post a Comment