Scopes and Pointers : <p>This is the code that I have a question about: </p>

<pre><code>int* getPtrToFive() {   
   int x = 5;   
   return &amp;x;
}  
int main() {   
   int *p = getPtrToFive();   
   cout &lt;&lt; *p &lt;&lt; endl; // ??? 
}
</code></pre>

<p>The lecture slides say that *p wouldn't give a valid result because as getPtrToFive is returned, x goes out of scope. However, I thought that getPtrToFive would already contain the value of 5, which would validate *p? Is it because of the pointer trying to direct me to getPtrToFive which has an out of scope x? </p>
