what is Void Pointer?

Void pointer or generic pointer is a special type of pointer that can be pointed at objects of any data type. A void pointer is declared like a normal pointer, using the void keyword as the pointer’s type.

Pointers defined using specific data type cannot hold the address of the some other type of variable i.e., it is incorrect in C++ to assign the address of an integer variable to a pointer of type float.


float *f; //pointer of type float
int i;  //integer variable
f = &i; //compilation error

The above problem can be solved by general purpose pointer called void pointer.

Start exploring endless computing possibilities with your own Raspberry Pi computer and accessories. Perfect for beginners and students.

Void pointer can be declared as follows:

void *v // defines a pointer of type void

The pointer defined in this manner do not have any type associated with them and can hold the address of any type of variable.


void *v; 
int *i;
int ivar;
char chvar;
float fvar;
v = &ivar; // valid
v = &chvar; //valid
v = &fvar; // valid
i = &ivar; //valid
i = &chvar; //invalid
i = &fvar; //invalid

14 Responses to “what is Void Pointer?”

  1. Mitul Patel (MCA)

    Good material are produce by ur website. plz give us to better and better materials. thanks a lot

  2. resham

    explanation given in very simple language.awesome description.thnx

  3. frends jahan tak maine is topic ko samjha hai wo ye hai ki generic pointer is also known as void pointer as we know ki har pointer ka ek data type hota hai but yahan hum koi specific data type ke saath pointer declare nai karte balki void is keyword which use in as data type at the time of generic/void pointer concept…..ye pointer vo hai jiski value yani uska data type kabhi bhi hum typecast karsakte hain by using

    Ex: float *float_pointer;
    int *int_pointer;
    void *void_pointer;
    . . . . . . . .
    . . . . . . . .
    void_pointer = float_pointer;
    . . . . . . . .
    . . . . . . . .
    void_pointer = int_pointer;

    A void pointer is generally used as function parameters, when the parameter or return type is unknown.

  4. sailakshmi bhashyam

    void main()
    int i=5;
    printf(“in do”);

    • Julissa

      smartman is wrongno attacking mermaids love life…not fair. Its a newday in 2012 and we will keep the attacks only atthose who attack us first.happy new year mermaid…nice ar8&3lei#t2c0;.would love to see yu again…its been about 8 years!

    • Florence

      NicménÄ› tabletům není proč se vyhýbat. KocÅnkonce¯ se dají využít k prezentaci pravého úhlu a dokonce i jako odrazná plocha, nemluvÄ› o velmi atraktivní demonstraci volného pádu.

  5. Yep, same thing is happening regarding what Pixel Patriot stated, WEIRD!:Pixel Patriot | December 30, 2010 at 10:15 am | CWGood morning. FYI When I click on your Home link at the top of your website it redirects me to the post from the 29************.*t****h*****bob strauss | December 30, 2010 at 10:40 am | CW, I hit my normal bookmark, and it took me to the Dec 29th post also. I had to go back on my computer to get back to today’s post.


Leave a Reply