How do I make sure it's safe to return a pointer from a function
<p>Here's my problem:
I read here on StackOverflow that it is unsafe sometimes to return pointers to local variables from a function. For example:</p>

<pre><code>#include&lt;iostream&gt;

using namespace std;

int *foo(void) {
    int x[] = {1,2,3};
    return x;
}

int main() {
    int *numbers;
    numbers = foo();
    return 0;
}
</code></pre>

<p>I'd like to know if this is unsafe, considering that <code>x</code> being a local array, the memory could be unallocated, what's the better way to achieve the same result?</p>
