Erik Fredericks, frederer@gvsu.edu Fall 2025
Based on material provided by Erin Carrier, Austin Ferguson, and Katherine Bowers
Two areas of memory
The stack is a stack data structure
The heap is not necessarily a heap
Variables are in one or the other
So far, we've only dealt with the stack
New block (scope) for each function called
Dynamically allocated memory
We must free any memory we allocate
Stack allocates / deallocates automatically
Heap allows flexibility, but require more thought
Stack
int x;
char arr[20];
Heap
malloc();
realloc();
heap grows up, stack grows down
variable length array, allowed in c99 size an issue for stack limited systems (ie embedded)