title: C++ Returning reference to local variable
body: <p>Is the following code (func1()) correct if it has to return i? I remember reading somewhere that there is a problem when returning reference to a local variable. How is it different from func2()? </p>
  
  <pre><code>int&amp; func1()
  {
      int i;
      i = 1;
      return i;
  }
  
  int* func2()
  {
      int* p;
      p = new int;
      *p = 1;
      return p;
  }
  </code></pre>