malloc allocates a specified number of bytes during program execution and returns a pointer to that storage, or a null pointer on failure. It supports dynamic allocation when fixed-size objects cannot accommodate growing collections or irregular data. Include stdlib.h when using malloc and its related interfaces. section 13.1
Allocating a vector
A vector containing one double for each living person can be allocated by multiplying its length by the size of one element. Writing sizeof *largeVec expresses the element type through the pointer and keeps the allocation correct if the pointer type changes. malloc itself knows neither the eventual type nor its later use; it receives only a byte count. section 13.1
Use malloc alongside the rules governing allocated storage:
- Pair every allocation with a corresponding free; failing to do so can create a memory leak and resource exhaustion. section 13.1.2
- Pass free only a pointer returned by malloc, calloc, aligned_alloc, or realloc, or a null pointer—not a subobject, ordinary variable, or already-freed pointer. section 13.1.2
- Treat calloc, realloc, and aligned_alloc as specialized allocation interfaces: they clear storage, resize storage, or ensure nondefault alignment. section 13.1

