title: Confused about basic recursion in C++
body: <pre><code>void print(int p)
  {
      if (p==0)
      {
         return;
      }
  
      print(p-1);
      cout&lt;&lt;p;
      return;
  }
  </code></pre>
  
  <p>This is a basic function which counts up from whatever number you input so if you send 6 it prints 123456. </p>
  
  <p>I've been staring at this for like half an hour and I can't figure out how it works. Why doesn't the recursive call <code>print(p-1);</code> just lead to the statement <code>if(p==0)</code> and return before ever even reaching <code>cout&lt;&lt;p</code>?</p>
  
  <p>How is <code>cout&lt;&lt;p</code> ever accessed? I completely understand how it works when <code>cout&lt;&lt;p;</code> is put BEFORE the recursive call and prints like 654321 instead.</p>