a void *
can do nothing more than a char *
I'm not sure about which can do more things than another but I'm sure that void*
can do his own jobs which char *
(or any other type of pointer) cannot.
void*
is known as a generic pointer. Generic pointer:
- Can hold any type of object pointers
- Cannot be dereferenced
- Especially useful when you want a pointer to point to data of different types at different times
And if you try hard to make char*
do something that void*
can do, it may possible but will lead to assumption.
If even the compiler does not inform an error or at least a warning about incompatible type, we still don't want to see this kind of code:
//hi guys, the argument is char* type
//but you still can pass any other pointer types
//don't worry!
void func(char * p) {
...
}
We just need this:
//this comment is not need, right?
//you know that you can pass any pointer types
void func(void* p) {
...
}