Realloc
realloc is a C standard-library function that changes the size of an allocated memory block while preserving its existing contents up to the applicable size.
Modern C, Third Edition
realloc is a C library function that changes the size of an allocated storage region while preserving its existing contents up to the applicable size.
- How it is used
- Resizes dynamic arrays and output buffers while retaining their existing contents.
- How deep it goes
- Explains return values, relocation, preserved contents, pointer invalidation, and failure cleanup, without prescribing how the runtime chooses an address.
- Examples
- Uses circular-buffer growth and an optimized number-printing buffer that doubles its capacity.
- What you can do after
- Build it from scratch: resize an allocated buffer, check failure before replacing its pointer, and arrange cleanup.
Modern C
realloc is a C standard library function that changes the size of a previously allocated memory block while preserving its existing contents up to the applicable size.
- How it is used
- Uses realloc to grow or shrink dynamically allocated storage while implementing a variable-capacity circular buffer.
- How deep it goes
- Explains return-pointer relocation, prefix preservation, failure checks, and allocation accounting, while deferring broader implementation details.
- Examples
- Demonstrates realloc on a double array backing a circular buffer whose live data may occupy two wrapped chunks.
- What you can do after
- Apply it via stdlib.h to resize allocated arrays, check failure, update the owning pointer, and preserve or relocate live data safely.
Related concepts
- mallockind of · malloc is a C standard-library function that allocates a specified number of uninitialized bytes and returns a pointer to the storage or a null pointer on failure.
- freecontrasts with · free is a C standard-library function that releases dynamically allocated storage previously obtained from a compatible allocation function.
- exceptionuses · An exception is a runtime signal or object representing an abnormal condition that interrupts ordinary program flow and may be handled or propagated.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

