Dynamic allocation obtains and releases storage during program execution, allowing programs to handle growing collections, irregular data, large matrices, and streams. Unlike declared variables or compound literals, allocated storage begins as a byte array without object type; it acquires interpretation when a value is stored. section 13.0 section 13.1
Allocating a vector
A vector of doubles can be allocated with malloc using a byte count based on the pointed-to type: `malloc(length * sizeof *largeVec)`. Writing the pointed-to type only once lets the allocation adapt if the pointer type changes. Release the storage with free when it is no longer needed. calloc provides zeroed bits, realloc grows or shrinks an allocation, and aligned_alloc requests nondefault alignment. section 13.1
Manage allocated storage with explicit ownership and matching operations:
- Pair every allocation with a free; missing releases can create memory leaks and resource exhaustion. section 13.1.2
- Use free only with pointers returned by malloc, calloc, aligned_alloc, or realloc, or with null pointers. section 13.1.2
- Remember that realloc may both release the old allocation and create a new one, complicating simple allocation counts. section 13.1.2
The allocation functions operate through void pointers, so the interface carries no type information and can serve different object types. Allocation therefore requires deliberate size calculation, initialization, lifetime tracking, and eventual release. section 13.1 section 13.6










