Skip to main content

Practice · 3 of 4

Grow and Preserve

CHALLENGE
Difficulty: beginner+25 XP

A dynamic array grows by DOUBLING when full: implement int* grow(int *old, int old_cap) returning a new block of 2*old_cap ints whose first old_cap elements equal the old ones. Free nothing — the CALLER still owns old. Return NULL on failure.

Back to lesson: Practice: Allocation Workbench