Casting a void pointer to a struct

℡╲_俬逩灬. 提交于 2019-12-03 04:48:53
(struct data*)pointer

will cast a pointer to void to a pointer to struct data.

Typecasting void pointer to a struct can be done in following

void *vptr;
typedef struct data
{
   /* members */
}tdata;

for this we can typecast to struct lets say u want to send this vptr as structure variable to some function

then

void function (tdata *);
main ()
{
    /* here is your function which needs structure pointer 
       type casting void pointer to struct */

    function((tdata *) vptr);
}

Note: we can typecast void pointer to any type, thats the main purpose of void pointers.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!