Lesson 17 of 50
cDynamic Memory – malloc & free
12 mins
Course progress34%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 17 of 50
c12 mins
Keep these ideas in mind as you work through the lesson.
The heap provides memory at runtime via <stdlib.h> functions:
void *malloc(size_t size) – allocate uninitialized memory.void *calloc(size_t count, size_t size) – allocate zero‑initialized memory.void *realloc(void *ptr, size_t newSize) – resize an existing block.void free(void *ptr) – return memory to the system.Always check the pointer returned by malloc/calloc for NULL. Forgetting free causes memory leaks; double‑free leads to undefined behavior.