C Tutorial thirteen published on allocating memory
I’ve restricted this tutorial to using malloc as it’s the main way you allocate and use dynamic memory in the thirteenth tutorial.
Pointers hold an address (of somewhere in RAM) and this can be an existing variable, a function or even data like a text string. But if you want to reserve a block of RAM and get a pointer to it, you have to call the stdlib function malloc(). (Or calloc, but I will return to that in a future tutorial).
Of course once you’ve finished using a block of RAM, it’s only polite to return it to the operating system by calling free(). Don’t forget either that malloc always returns a void * pointer, so you should cast it to something appropriate.