🧠Go deeper — read the bookA process's memory layout— runnable code & full walkthrough →

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 -> .data
static int s; // uninitialized static -> .bss
const char* msg = "hi"; // "hi" -> .text ; msg -> stack
int main() {
int x = 1; // local -> stack
int* p = new int(7); // p -> stack ; *p -> heap
}

What this lesson walks through

  1. 01A process's virtual address space
  2. 02Code & literals live in .text (read-only)
  3. 03Initialized globals -> .data
  4. 04Uninitialized statics -> .bss
  5. 05String literal -> .text ; pointer -> stack
  6. 06Locals live on the stack (grows down)
  7. 07new allocates on the heap (grows up)
  8. 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.

← Previous
Open Addressing — Cache-Friendly Hash Maps
Next →
IPC: Pipes & FIFOs — Unidirectional Byte Streams Between Processes