When the stack does not have enough room for what we wish to store, or when we wish to allocate some memory and have it persist after the function that allocates it returns, we need to place the memory somewhere else. That somewhere else is the heap (also known as the free store).
The memory space for a program is broken up into different segments that each have a different purpose. One segment is used to store the actual code of the program. Another segment is used to store global variables. A third segment is used for the stack. Those segments are all fixed as the program starts running. That is why you can have a stack overflow - the stack βgrowsβ from the βbottomβ (highest address) towards its lowest address and if the βtopβ ever grows past that lowest address, it has overflowed.
The heap is another such segment. It is not organized in a strict manner like the stack. Instead, it is a large pool of memory that can be allocated and deallocated as needed. (The name βheapβ should evoke the idea of a messy pile of things from which we can freely add or remove things.)
Not every computer system organizes memory into these segments, and the specifics can vary based on the architecture and operating system. In particular, small embedded systems may not have a traditional heap at all. But all typical desktop, server, and mobile systems use a memory management scheme like the one described here.