Guided Notes

Dynamic Memory Management

Stack vs heap, malloc, calloc, realloc, and free, checking for NULL, memory leaks, and dangling pointers.

Stack and heap

Slide 1 / 5
StackHeap
HoldsLocal variables, function callsMemory you request at run time
SizeSmall (often ~8 MB)Large — most of RAM
LifetimeFreed automatically when a function returnsUntil you call free()
Managed byThe compilerYou (malloc / free)
← Structs & Enums