Skip to content
UPEEC

Stack vs Heap

Automatic local variables live on the stack (fast, limited, freed on return); `malloc` memory lives on the heap (flexible, manual).

Easy
Comments 0

Never return a pointer to a local variable. On microcontrollers the stack may be only a few KB — avoid large local arrays and deep recursion.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.