malloc is for "memory allocation". While programming, we very often need to allocate free memory for variables of unknown length, which can not be decided at the time of programming. E.g. a program prompts people's names; since each person's name is different, the programmer is unlikely to allocate a fixed amount of memory to hold their names. (You may argue that it is possible to assign a whole bunch of memory; it is a bad practise and it is problem prone. )
A similar function is calloc().
A very good book to learn C language is C programming, A modern approach by K.N.King.