Look into malloc. The *alloc functions are used to dynamically create arrays. They're created on something called the heap, and when you're programming, you need to make sure that things that are allocated on the heap are cared for properly, or you can start having memory leaks. In your case, you have somewhat taken care of it by making it static. The other major way to do things is to have the caller of the function free the memory when it's done with it.
Your usage should be something like this:
double * my_function(int length)
{
static double * arr = NULL;
if (arr == NULL) {
arr = malloc(length * sizeof(double));
}
return arr;
}
Note, by having the static and putting the wrapper around it as I did, this is setting arr up to fit a singleton design.
The non-singleton alternative is:
double * my_function(int length)
{
static double * arr = NULL;
if (arr != NULL) {
free(arr);
}
arr = malloc(length * sizeof(double));
return arr;
}
This one reallocates each time it is called. Any function that saved the return value from my_function would then find it to be out of date.