Appearance
3. Why Stack Grows Downward & Heap Grows Upward
They grow toward each other so they share the free middle space efficiently — neither reserves a fixed size upfront.
Why stack grows down: a hardware/historical convention. Early CPUs (x86) were built so the stack pointer starts high and decrements on PUSH. The OS and compilers just followed the CPU's native behavior.
Why heap grows up: the heap is managed by the userspace allocator (malloc), not CPU hardware, so it made logical sense to start low and grow up — simple and non-conflicting with the descending stack. The OS extends it via the brk()/sbrk() syscall.
If they collide: stack overflow (too much recursion) or heap exhaustion. The OS places a guard page between them — touching it triggers a segfault before real corruption happens.
Modern caveat: with virtual memory, each process gets a huge address space (e.g., 128TB on 64-bit Linux), so stack and heap almost never actually collide — but the down/up convention persists for compatibility.