realloc
Resizes an allocation, possibly moving it.
Intermediate
int *tmp = realloc(a, new_n * sizeof *a);
if (!tmp) { /* a is still valid! */ } else a = tmp;
Never write a = realloc(a, …) — on failure you leak the old block.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.