Stack variables disappear when a function returns. malloc takes bytes from the heap and you must free them.
The stack is automatic: int x dies when the function returns. The heap is a warehouse you rent with malloc and must give back with free. Dynamic memory is that warehouse.
heap box
write
7
release
Each step highlights the matching C line. Program output appears only when a line that prints actually runs.
Five questions. Pick one answer each, then Check answers. The correct choice turns green.
1. malloc(sizeof(int)) asks for:
Heap.
2. If malloc returns NULL:
Check.
3. free(p) does:
Release.
4. Using *p after free is:
Dangling.
5. calloc vs malloc:
Zero fill.