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...
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement