This linked article introduces the concept of stack and heap as well as their difference.
http://gribblelab.org/CBootcamp/7_Memory_Stack_vs_Heap.html
Stack:
Access fast
Allocate and release memory automatically by CPU
Has a size limits
Variables can't be resized
Variables accessed locally
Heap:
Allocate and release memory by yourself
no limits on memory size( has physical memory size limits )
Variables can be resized using realloc() function
Variables accessed globally
When to use heap:
1\ You want a allocate a large block of memory and keep variables around a long time.
2\ You need variables like arrays or structures that change their size dynamically