- [Educator] The void type has special meaning in C++.
It's used to specify lack of value
for function parameters and function returns.
This is void-type.cpp from chapter three
of the exercise files,
and you see that this function
has a void return type and a void parameter type.
So as a return type, it means this does not return anything,
and so no return statement is required.
In fact, it's not even allowed.
If I say return 3
and try and build this,
you see, I'm not allowed to return a value.
I am allowed to simply say return without a value
but I'm not allowed to return a value
because of the void return type.
As a parameter type,
this is one of the few significant differences from C.
In C, the void type in the argument list
means that the function takes no arguments.
Because in C, a function declaration
with an empty argument list
does not mean that the function takes no arguments.
In C++, a function declaration with no arguments
actually does mean that this function takes no arguments.
So the usage with void is simply allowed
for compatibility with C but it's not required.
More often, you'll see it
with just an empty argument list like that.
So while void is syntactically a type,
it's only used in special circumstances.
As a return type or as a parameter type.
And its value is to enforce a rule
preventing use where a value would be expected.