Growing memory with realloc
Grow a heap block with realloc, see why its address can change, keep the old pointer safe, and build a dynamic array that doubles its capacity.
- The skill
- Grow and shrink heap blocks with realloc without losing data or leaving stale pointers behind.
- You make
- A sensor log that grows as readings arrive and a game replay buffer that records frames and trims itself.
Premium lesson
£7.99 a month or £59 a year. Cancel any time.
Builds on 19 The heap and malloc. Free to try: C Foundations and the playground.
Passed
You can now
Keep going
Step 1 of 9
exercise_1.c
You've reached the good stuff.
5 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.
C, 32-bit: int and pointers are 4 bytes