pointers-memory · intermediate · ~15 min
Allocate + copy. The motivating concept of "deep" vs "shallow" copy.
Implement int *copy_ints(const int *src, size_t n) returning a freshly allocated array with the same contents. If n == 0 you may return NULL.
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
int *copy_ints(const int *src, size_t n) {
/* TODO */
return NULL;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.