1. Text Segment (Code Segment):
- Contains the compiled code of the program.
- This segment is usually read-only to prevent accidental modification.
- It stores functions and executable instructions.
2. Data Segment:
- Initialized Data Segment: Stores global and static variables that are explicitly initialized by the programmer.
- Uninitialized Data Segment (BSS): Stores global and static variables that are not initialized by the programmer (defaulted to zero).
3. Heap Segment:
- Used for dynamic memory allocation.
- Memory is allocated using functions like
malloc
, calloc
, realloc
, and freed using free
.
- Grows upwards as more memory is allocated.
4. Stack Segment:
- Used for function calls, local variables, and storing return addresses.
- Grows downwards as new functions are called.
- Each function call creates a stack frame containing its local variables and control information.
5. Command-line Arguments and Environment Variables:
- Stored in memory just before the stack segment.
- These are passed to the program at runtime and accessible via
argc
and argv
parameters in main
.