Here's the deal (and folks, this is a legit beginner question, jaysus, lay off the guy.)
The void
type in C and C++ is a tag or label for "thing of no type at all." Now, when we talk about the "type" of something, we're really saying two things:
- how much memory does it occupy?
- what operations can we perform on that thing?
So, for example, when we declare something like int x;
we're saying that x
- is
sizeof(int)
× 8 bits of memory
- has arithmetic operations like
*
and +
.
Now, an object of no type would have neither one, so the compiler tells you the size is unknown or 0.
But what is useful is to have an address that doesn't have a type associated with it. When you declare something as int * xp;
you're saying thet xp
is the address of something that we agree to treat as an int
-- but it's just an agreement because we can, eg with a typecast, change or minds later.
When we declare something void * vp;
, we're saying "this is the address of something, type of that something to be determined later."