title: Return address of local variable in C
body: <p>Say I have the following two functions:</p>
  
  <p><strong>1</strong></p>
  
  <pre><code>int * foo()
  {
    int b=8;
    int * temp=&amp;b;
    return temp;
  }
  </code></pre>
  
  <p><strong>2</strong></p>
  
  <pre><code>int * foo()
  {
     int b=8;
     return &amp;b;
  }
  </code></pre>
  
  <p>I don't get any warning for the first one (e.g. <em>function returns address of a local variable</em>) but I know this is illegal since <code>b</code> disappears from the stack and we are left with a pointer to undefined memory.</p>
  
  <p>So when do I need to be careful about returning the address of a temporary value?</p>