In C you cannot have multiple functions with the same name. Like this:
- int Area(Circle* x);
-
int Area(Square* x);
-
int Area(Triangle* x);
The workaround is to use a void pointer. The keyword void just means "no-type". The you supply a second argument to explain the void pointer:
- int Area(void* x, int y);
May y=1 means the x argument is a Circle whereas y = 2 may mean the x argument is a Square.
This allows the function to typpecast the void* to the correct type and do the calculation.
This situation does not arise in C++ where function names are identitifed by their signature and not by their names.
The other place you see void is as a function return type:
This tells the compiler that no type is returned making this an error:
Without the void return, the function is assumed to return an int. Now the code passes the compile OK but crashes at run time when val is garbage.