liveBook · Manning

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.

How 2 Manning books explain it

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.

Read how Modern C, Third Edition explains realloc →

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.

Read how Modern C explains realloc →

Related concepts

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.