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
- Uses realloc to resize dynamic storage while preserving existing data.
- How deep it goes
- Explains content preservation, pointer invalidation, failure handling, and allocation cleanup through worked code.
- Examples
- Demonstrates resizing a circular buffer and growing a formatted-output buffer.
- What you can do after
- Apply it via the C standard library to resize buffers, check failure, and retain a valid pointer for 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.
What to know first
- resource exhaustionResource exhaustion is a condition in which a program or system cannot obtain enough of a required resource to operate normally.
Related concepts
- mallockind of · malloc is a C standard-library function that allocates a specified number of bytes of uninitialized storage and returns a pointer to it or a null pointer if allocation fails.
- 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 value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
Questions about realloc
What is 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.
Which Manning books explain realloc?
Modern C, Third Edition and Modern C.
What should I know before learning realloc?
Manning books that teach realloc usually introduce resource exhaustion first.
What is the difference between realloc and free?
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. free is a C standard-library function that releases dynamically allocated storage previously obtained from a compatible allocation function.
What is realloc a kind of?
Realloc is a kind of malloc. malloc is a C standard-library function that allocates a specified number of bytes of uninitialized storage and returns a pointer to it or a null pointer if allocation fails.
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.

