void and void pointer

Home Forums C-programming.. void and void pointer

  • This topic has 1 reply, 1 voice, and was last updated 3 weeks ago by Adroitix.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #3405 Reply
    Humble
    Keymaster

    Lets see whats the size of void and void pointer.

    [hchiramm@humbles-lap forblog]$ cat voidp.c
    #include
    int main()
    {
    int x = 5;
    void *pv = &x;

    printf (“sizeof(void) :%d \t sizeof (void pointer) :%d \n New address %p \n” , sizeof(void) ,sizeof(pv), pv );
    pv = pv + 1;
    printf (“New address %p \n” , pv );
    }

    [hchiramm@humbles-lap forblog]$ ./voidp
    sizeof(void) :1 sizeof (void pointer) :8
    New address 0x7fff41850a44
    New address 0x7fff41850a45
    [hchiramm@humbles-lap forblog]$

    As shown above , void size has been printed as “1” and Void pointer size has been printed as “8” in my system.
    NOTE: In some compilers, the arithmetic operation on void pointer will result in “SYNTAX ERROR” ..

    VOID POINTER

    Any pointer can be assigned to a void pointer. However void pointers are for data pointers and not for function pointers. void pointer can then be cast back to its original pointer type to get the original pointer value intact.

    For ex:

    int x;
    int *mi = &x;
    // [1]
    void *vp;
    vp = mi;
    mi = (int *)vp
    // [2]

    at [1] and [2], the value of “mi” will be same.

    #6227 Reply
    Adroitix
    Guest

    Adroitix is a trusted pharma engineering consultancy specializing in end-to-end greenfield project development for pharmaceutical and biotech industries. From concept design, master planning, and regulatory engineering to cleanroom, utility, and process integration, we deliver fully compliant, future-ready facilities. Our expertise ensures optimized layouts, sustainable operations, and seamless project execution from land selection to plant commissioning.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: void and void pointer
Your information: