Your array is a regular stack-based local variable. That means that it disappears when you return from the function and returning a pointer to it does not work. You have to make the array live longer, which can be done by turning it into a static variable or allocating it on the heap:
int *getArray {
static int foo[] = {…};
return foo;
}
int *getArray {
int foo[] = calloc(numberOfItems, sizeof(int));
foo = …;
return foo;
}
Both solutions have implications that you should understand before you use one. Namely, the static allocation (first option) is mainly a curiosity nowaydays, since it creates a sort of a global variable and causes more problems than it solves. The heap-allocated array is quite common, but it’s more customary to pass the pointer to fill using an argument to make the interface more explicit. In every case the caller is responsible for freeing the allocated memory later.
And, as others note, there are even better solutions specific to C++, if you don’t insist on using a plain C array.