Lesson 17 of 50 · c
Dynamic Memory – malloc & free
Duration: 12 mins
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.