When something is cast to void, then the value becomes NULL
. However, why does a void *
point to any data type? Shouldn't a void pointer just be useless?
A void pointer is a pointer to anything. It is a generic pointer that doesn't have a particular type. It can also have the value NULL
in which case it doesn't point to anything.
To use a void pointer, you have to keep track of what it actually points to and when you are going to use it, you must cast it to the appropriate type.
They can be dangerous, because if you cast it to the wrong type, it will result in undefined behavior at runtime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With