malloc is a C++ library function that allocates the requested memory and returns a pointer to it. This is called dynamic memory allocation and allows for memory allocation on the go. It is the predecessor to the C++ new operator used for memory allocation.