To understand the way our C program works, we need to understand the arrangement of the memory assigned to our program.
All the variables, functions, and data structures are allocated memory into a special memory segment known as Data Segment. The data segment is mainly divided into four different parts which are specifically allocated to different types of data defined in our C program.
The parts of Data segments are :
It is the permanent memory area. All static and external variables are stored in the data area. The variables which are stored in the data area exist until the program exits.
It is the memory area which can only be accessed by the function pointers. The size of the code area is fixed.
As we know that C supports dynamic memory allocation. C provides the functions like malloc() and calloc() which are used to allocate the memory dynamically. Therefore, the heap area is used to store the data structures which are created by using dynamic memory allocation. The size of the heap area is variable and depends upon the free space in the memory.
Stack area is divided into two parts namely: initialize and non-initialize. Initialize variables are given priority than non-initialize variables.