You are right that a function return a void is not returning anything. However, this function returns a type of (void *). I wrapped it in parenthesis so you can see it as a singular type. In the Windows SDK they have wrapped it in a type definition :
typedef void * PVOID;
This lets you refer to it as a PVOID. The difference here is a void * is an un-typed pointer. It could point to any possible kind of data. As the other solutions show, you have to cast the result of malloc (and calloc and realloc) to the type of the data you are using. Here's a handy little macro that will do the casting for you :
#define AllocateMemory( count, type ) (type*)calloc( count, sizeof( type ) )
This uses calloc which is just like malloc except it zeros the memory for you automatically which I find very useful. If you want a bunch of integers you can call it like this :
int * intArray = AllocateMemory( 137, int );
and that will allocate memory for 137 integers and set them all to zero.
In C++ it is best to use an automatic memory class like a
unique_ptr. [
^].