Values & References13 / 18
Up next

Heap ownership

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int *buf = malloc(3 * sizeof *buf);
    for (int i = 0; i < 3; i++) {
        buf[i] = i * i;
    }
    printf("%d %d %d\n", buf[0], buf[1], buf[2]);
    free(buf);
    return 0;
}
What you're solving

malloc gives a pointer you must free