pointers-memory · intermediate · ~15 min
Allocate, initialise, and return heap memory.
Implement int *make_range(int n) that allocates an array of n ints with malloc, fills it with 0,1,...,n-1, and returns it. The caller frees it.
#include <stdlib.h>
int *make_range(int n) {
/* TODO */
return NULL;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.