EmbLogic's Blog

what is void * ??

please explain void *

4 Responses to what is void * ??

  1. dhanashri says:

    Pointer is a variable that points to the variable element to which it is defined. Example, int *ptr, this is the pointer which is pointing to the int var element. Void *, points to any user defined data type, so same pointer can be used in a program for various data types. Only thing, you need to type cast it whenever you use it with any data type.
    Ex is explained below for this:

    int main()
    {
    void *ptr;
    int i;
    char ch;
    float h;
    i = 10;
    ptr = &i;
    printf(“%d\n”,*(int *)ptr);
    ch = ‘c’;
    ptr = &ch;
    printf(“%c”,*(char *)ptr);
    h = 56.9;
    ptr = &h;
    printf(“%f”,*(float *)ptr);
    }

  2. dhanashri says:

    Void pointer is a pointer that points to user defined data element. The advantage of void pointer is, same pointer can be used for various tasks by type casting it. Example is explained here.

    int main()
    {
    float fl;
    int i;
    char ch;
    void *ptr;

    ch = ‘c’;
    ptr = &ch;
    printf(“%c\n”,*(char *)ptr);

    i = 10;
    ptr = &i;
    printf(“%d\n”, *(int *)ptr);

    fl = 12.0;
    ptr = &fl;
    printf(“%f\n”, *(float *)ptr);

    return 0;
    }

  3. Mandar says:

    Basically void means “nothing” or “no type”

    There are 3 basic ways that void is used:

    1) Function argument: int myFunc(void) — the function takes nothing.

    2) Function return value: void myFunc(int) — the function returns nothing

    3) Generic data pointer: void* data; — ‘data’ is a pointer to data of unknown type, and cannot be dereferenced.
    finally we can say that void indicates the absence of type, it is not something you can dereference or assign to.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>