Memory Layout of C Programs
A typical memory representation of C program includes of the following sections.
1. Text segment
2. Initialized data segment
3. Uninitialized data segment
4. Stack
5. Heap
1.Text segment:
A text segment , also known as a code segment, is one of the sections of a program in an object file or in memory file, which are contains executable instructions.
2. Initialized data segment:
Initialized data segment, usually called simply the Data Segment,It is permanent memory area or permanent memory block. so All the external and static variables are stored in the text Area. The variables that are stored in the data area exist until the program exits.
3. Uninitialized data segment:
The Uninitialized data segment, also called the “bss” segment, The program loader allocates memory for the BSS section when it loads the program,It contain all uninitialized global and static variable. so in this segment All variables initialized by the (0)zero and the pointer with the null value.
4. Stack Area
The Stack area is divided into two parts namely first initialize and second non-initialize. Initialize variables are given priority than non-initialize variables.
5. Heap
This is dynamically allocated memory to a process at the run time. This is area of memory allotted for dynamic memory storage such as for malloc() and calloc() calls. This segment size is also variable as users process program. This segment grows from a lower address to a higher address.