
The stack is used for managing function calls and local variables.
Local variables, function parameters, and return addresses are stored here.
Automatically managed by the operating system.
Data structure: LIFO
The heap is used for dynamic memory allocation.
Memory allocation is not automatically managed by the OS, and is larger than the stack. It is the programmer’s responsibility to allocate and deallocate memory.
This segment holds global and static variables that are declared but not initialized by the programmer.
Example:
static int x;
Without an explicit value, it will be stored in the BSS segment.
This segments holds global and static variables explicitly initialized by the programmer
Example
static int x = 1;
Memory is allocated for these variables at the start of the program and persists until the program terminates.
The text segment contains executable code of the program. It is where instructions for the CPU is stored.
Typically read-only to prevent accidental modification of instructions during execution.