pointers-memory · intermediate · ~15 min
Complete the alloc/use/free lifecycle in one function.
Implement long sum_then_free(int n) that allocates an n-int array, fills it with 1..n, computes the sum, frees the array, and returns the sum. No leaks.
#include <stdlib.h>
long sum_then_free(int n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.