title: C++ Scope of Pointer?
body: <p>I have a question
  For example I have code below:</p>
  <pre><code>
  void function1()
  {
      Car car;
      car.color = 10;
      carPtr = &amp;car;
      std::cout &lt;&lt; carPtr-&gt;color;
  }
  
  void function2()
  {
      std::cout &lt;&lt; carPtr-&gt;color;
  }
  
  int main()
  {
      function1();
      function2();
  }
  
  </code></pre>
  <p>This code for some odd reason works.
  If I created a instance of car in the scope of function1() then why am I able to use car in function2()???
  Should'nt have carPtr pointed to nullptr the moment it left function1() because car exists in the scope of function1()
  is the data for the &quot;car&quot; object being copied into function2() and how would that work??? Can someone explain what is going on please? Thanks in advance!</p>