os ipc · high
Process Memory Layout
Where every variable lives - stack, heap, .bss, .data, .text - and how the stack and heap grow toward each other.
🔑 Key line
Five regions: stack (grows down), heap (grows up), .bss (zeroed), .data (initialized), .text (code/rodata).
The code
int g = 42; // initialized global -> .datastatic int s; // uninitialized static -> .bssconst char* msg = "hi"; // "hi" -> .text ; msg -> stackint main() { int x = 1; // local -> stack int* p = new int(7); // p -> stack ; *p -> heap}What this lesson walks through
- 01A process's virtual address space
- 02Code & literals live in .text (read-only)
- 03Initialized globals -> .data
- 04Uninitialized statics -> .bss
- 05String literal -> .text ; pointer -> stack
- 06Locals live on the stack (grows down)
- 07new allocates on the heap (grows up)
- 08The whole map
Every process gets a virtual address space split into regions. High addresses sit at the top, low at the bottom. Knowing what lives where explains lifetimes, sizeof, and crashes.
See it animated — step by step, at your own pace
Unlock the full interactive walkthrough of Process Memory Layout and 100+ animated C++ interview lessons.