In allocation, function memory is divided into program memory and data memory. Program memory consists of the memory used for main and functions. Data memory consists of permanent definitions, such as global data and constants, local declarations, and dynamic data memory.
How C handles these different needs is a function of the operating system and the compiler writer’s skills. Although the program code for a function may be in its memory at all times, the local variables for function are available only when it is active.
Furthermore, more than one version of the function can be active at a time. In this case, multiple copies of the local variables are allocated, although only one functional copy is present. The memory facility for these capabilities is known as stack memory. In addition to the stack, a memory allocation known as heap is available. Heap memory is unused memory allocated to the program and available to be assigned during its execution. It is the memory pool from which memory is allocated when requested by the memory allocation functions.
Static memory allocation requires the declaration and definition of memory to be fully specified in the source program. The number of bytes reserved cannot be changed during runtime. This is the technique used to define variables, arrays, pointers, and streams.
Dynamic memory allocation uses predefined functions to allocate and release memory for data while the program is running. It effectively postpones the data definition, but not the data declaration, to run time.