well void I thought means nothing void written or not written have no effect(in functions at-least) but still I guess C++ recognizes nothing as void I guess, so at declaration time if we want variable to be of no type then we ought to tell c++ with void keyword |
You can't have a void variable -- that wouldn't make any sense.
There are 3 general uses for void that I can think of:
1) As a return type to a function:
The 'void' cannot be omitted here. This indicates that the function does not return any value.
2) To indicate that you want a function to take no parameters:
1 2 3 4
|
int function(void)
{
return 0;
}
|
This is a C thing and not really C++.
In C++, no parameters means the function takes no parameters.
In C, no parameters means the function can take any number of parameters (similar to the C++ ellipsis)
So in C, to explicitly say the function has no parameters, you put the void in there. However this is completely unnecessary in C++.
3) void pointer:
A void pointer is another C-ish concept. The idea is that it's a generic pointer that can point to anything -- the data pointed to can be of any type.
This is typically avoided in C++ because it's not type safe.