The parts of Data segments are :
1. Data Area
It represents the non-volatile storage section where static and external variables are saved. The variables residing in this region persist throughout the program's execution lifespan.
2. Code Area
It represents the memory region exclusively accessible by function pointers. The dimensions of the code section remain constant.
3. Heap Area
C is known for its capability to support dynamic memory allocation. In C, developers rely on functions such as malloc and calloc to dynamically assign memory. Consequently, the heap region is designated to house data structures generated through dynamic memory allocation. The capacity of the heap region is flexible and is determined by the availability of free memory space.
4. Stack Area
Stack area is divided into two parts namely: initialize and non-initialize. Initialize variables are given priority than non-initialize variables.
- All the automatic variables get memory into stack area.
- Constants in c get stored in the stack area.
- All the local variables of the default storage class get stored in the stack area.
- Function parameters and return value get stored in the stack area.
- Stack area is the temporary memory area as the variables stored in the stack area are deleted whenever the program reaches out of scope.