What is better to return a pointer to an array for have the function set values in a existing array : What is considered better to have something like this:

    int * foo(int n) {
        int * output = new int[n];
        for (int i = 0; i < n; i++) {
            output[i] = i;
        }
        return output;    
    }
    
    int main() {
        int * arr = foo(10);
        return 0;
    }

and have the fuction return a pointer to the array or is it better to have something like this:

    void foo(int n, int output[]) {
        for (int i = 0; i < n; i++) {
            output[i] = i;
        }
    }
    
    int main() {
        int arr[10];
        foo(10, arr);
        return 0;
    }

where the function doesn't return anything but just sets the values of an array given in the parameters. Thanks.