C & Unix

Stack, Heap, malloc and free

7:39

Plays from YouTube. Watch on YouTube

Why can returning one pointer be valid while returning another creates a dangling address?

Meet Stack, Heap, malloc and free: an original animated lesson in C and Unix systems programming.

We start with automatic object lifetimes, then allocate a dynamically owned region using malloc.

From there, we work through free, leaks, dangling aliases, allocation-size errors, realloc failure and explicit ownership contracts.

The big idea: Every allocation needs a viable release path, and storing an address never extends an object's lifetime.

C and Unix explained visually, one concept at a time.