title: automatic instances vs new - creating object c++
body: <p>it is stated on this website: <a href="http://www.tutorialspoint.com/cplusplus/cpp_variable_scope.htm" rel="nofollow">http://www.tutorialspoint.com/cplusplus/cpp_variable_scope.htm</a></p>
  
  <blockquote>
    <p>Variables that are declared inside a function or block are local
    variables. They can be used only by statements that are inside that
    function or block of code. Local variables are not known to functions
    outside their own.</p>
  </blockquote>
  
  <p>Then, in the following example; </p>
  
  <pre><code>class foo {
      /*....*/
  };
  foo bar(){
      foo f;
      return f;
  }
  void main(){
      foo fooReturn = bar();
  }
  </code></pre>
  
  <p>how come when <code>bar()</code> returns, <code>fooReturn</code> contains a valid object?   is:
  <code>foo f</code> similar to <code>foo *f  = new foo();</code> are both objects on the heap?</p>
  
  <p>thanks
  daniel </p>