double* squares_copy(double a[], unsigned int alen) { double* res = (double*)malloc(sizeof(double) * alen); if (res == NULL) { fprintf(stderr, "squares_copy: unable to allocate result array\n"); exit(1); } unsigned int i; for (i = 0; i < alen; i++) { res[i] = a[i] * a[i]; } return res; } void baz() { double xs[] = {1, 2, 3}; double* ys = squares_copy(xs, 3); // ... use ys ... free(ys); }