C++ malloc() function is a Dynamic Memory Allocation function that allocates a block of size bytes from the memory heap. It allows a program to allocate memory explicitly as it is needed, and in the exact amounts needed. Many data structures, for example, trees and lists, naturally employ heap memory allocation.