Q:

Does delete [] arr frees up the memory if called outside the function in which the arr was created in C++?

Does delete [] arr frees up the memory if called outside the function in which the arr was created in C++?
I mean if I would have something like this
    double* f()
    {
    double* arr = new double[100];
    return arr;
    }

void ff()
{
double* arr = f();
delete [] arr;
}

Would be arr deleted properly in ff()?

A:

Yes, it will be deleted properly (same with delete). As long as you keep track of the pointer, you can delete it outside the function the memory was allocated in.

