Archived

This topic is now archived and is closed to further replies.

HappyDude

void *

Recommended Posts

HappyDude    122
I''m just wondering, what does it mean when you declare a variable a void *. I use it when I want to pass a multi-dimensional array to a function, and it''s used in fread/fwrite, but I want to know what exactly void * means...

Share this post


Link to post
Share on other sites
Martee    476
Well, it means that the region of memory pointed to doesn''t have any particular type. That is, you need to tell the compiler what is represented by the binary data by using a typecast.
void* memoryWithNoType = malloc(100);
char* p = (char*)memoryWithNoType;
This tells the compiler that when using the pointer p, the memory space in *memoryWithNoType should be interpreted as single byte ascii characters.

Share this post


Link to post
Share on other sites