Different layout of a C program is:
- Stack Segment
- Heap Segment
- Data segment
- Code segment or Text segment
Code Segment:
This is also referred as text segment and contains the executable and usually starts from low address and are static and read only part of memory.
Data segment:
This section of memory is responsible for holding global variables, static variables , constant and extern variables.
We cannot have two variables with the same name in this section.
This segment is further divided into two parts:
- Initialized data segment
- Uninitialized data segment
Initialized data segment:
This contains all the global, static, extern and constant variables which are initialized.
Uninitialized data segment:
This is also called as bss segment and contains all the global, static, extern and constant variables which are uninitialized.
bss is abbreviated as block starting symbol
Stack segment:
The stack section is used to store automatic variables (non-static local variables) and the calling environment each time a function is called.
Also all recursive function calls are added to stack. Data is added or removed in a last-in-first-out manner to stack.
Heap Segment: This segment is responsible for holding all the variables are which are dynamically allocated via malloc or calloc function.
The stack and heap are traditionally located at opposite ends of the process’s virtual address space.
Note:
We also have one segment called command line arguments section which holds the variable passed as command line argument.
int main( int argc, int *argv[])
Categories: C Language
Leave a Reply