typedef void *pointer

I am not clear about this type?

When we use this type, do we need to allocate memory for it?

Thanks!
Well I'm pretty sure a pointer has a static memory area...the void* just means it can point to any value (char, string, classes, etc).
void* points to any type of data; in order to use it, you must cast it to another valid pointer type (char*, etc.). So I believe it is valid to do something like:

void* ptr = new char;
However you would have to cast it to char* for most operations to make sense out of it. Hopefully someone more skilled can clarify this more for you.

Also, the code you have in the title is just a typedef. With a typedef like that, the following lines would be equivalent:

1
2
void* VoidPtr;
pointer VoidPtr;
Last edited on
Topic archived. No new replies allowed.