returning address of local variable is bad THEN why this code works
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope">Can a local variable&#39;s memory be accessed outside its scope?</a>  </p>
</blockquote>



<p>Returning the address of a variable inside a function is bad because that variable will no longer exist
if the stack frame where the variable belongs end.</p>

<p>So why this code works fine </p>

<pre><code>int* test(){
    int a = 11;
    return &amp;a;
}

int main(){

    int *a;
    a = test();

    cout &lt;&lt; *a;

    return 0;

}
</code></pre>
