In C, the header file required for memory allocation functions is stdlib.h. It declares the standard library routines malloc(), calloc(), realloc(), and free(), which let programs request, resize, and release dynamically allocated memory.
Dynamic allocation is useful when a program cannot know the required amount of memory at compile time. For example, a program reading an unknown number of records can allocate storage as data arrives, then enlarge it with realloc() when necessary. malloc() returns a pointer to uninitialized storage, while calloc() allocates space and initializes its bytes to zero.
A common mix-up is string.h, which provides string-handling functions such as strlen() and strcpy(), not the allocation routines themselves. stdio.h handles input and output, and math.h declares mathematical functions. The allocated memory comes from the heap, and every successful allocation should eventually be matched with free() to avoid a memory leak. Since C does not automatically reclaim unused heap memory, careful ownership and error checking are essential.