#include <stdlib.h>  // NULL, free, EXIT_SUCCESS, malloc

// allocate/copy a new array from a[]
// if malloc fails, returns NULL
int* Copy(int a[], int size);

int main(int argc, char** argv) {
  int nums[4] = {1, 2, 3, 4};
  int* nums_copy = Copy(nums, 4);

  // make sure copy succeeded by checking for NULL return
  if (nums_copy == NULL) {
    // out of memory
    return -1;
  }
  // .. do something with the array here ..

  // when you're done, free up the memory
  free(nums_copy);

  return EXIT_SUCCESS;
}

int* Copy(int a[], int size) {
  int i, *a2;

  a2 = (int*) malloc(size * sizeof(int));
  if (a2 == NULL) {
    // out of memory
    return NULL;
  }

  // do the copy
  for (i = 0; i < size; i++)
    a2[i] = a[i];

  return a2;
}