Best way of returning a pointer
<p>I have seen at least 5 C++ tutorial sites that return pointers this way:</p>

<pre><code>int* somefunction(){
    int x = 5;
    int *result = &amp;x;
    return result;
}
</code></pre>

<p>Is that not a very, VERY bad idea? My logic tells me that the returned pointer's value can be overwritten at any time. I would rather think that this would be the right solution:</p>

<pre><code>int* somefuntion(){
    int x = 5;
    int* result = new int;
    *(result) = x;
    return result;
}
</code></pre>

<p>And then leave the calling function to delete the pointer. Or am i wrong?</p>
