pointers-memory · intermediate · ~15 min
Grow a heap buffer and use realloc's returned pointer.
Implement int *append(int *a, int n, int v) that grows the n-element heap array a to n+1 with realloc, stores v at the new last slot, and returns the (possibly moved) pointer.
#include <stdlib.h>
int *append(int *a, int n, int v) {
/* TODO */
return a;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.