Skip to main content

Practice ยท 2 of 3

Push with Grow

Given int da_push(DArray *a, int v) exists in spirit, implement int da_push2(DArray *a, int v): append v; when size == cap, DOUBLE cap (cap 0 becomes 4) via realloc; return 1 on success, 0 on realloc failure (leaving the array intact).

Difficulty: beginner

Back to lesson: Practice: Dynamic Array Build