title: Incrementing iterator and passing the argument in a recursion loop
body: <p>I want to print out the values of a vector using a recursive function.</p>
  
  <pre><code>void pvec(int cnt, std::vector&lt;int&gt; vec) {
      if(cnt &lt; vec.size()) {
          std::cout &lt;&lt; vec[cnt++] &lt;&lt; std::endl;
          return pvec(cnt,vec);
      }
  }
  </code></pre>
  
  <p>Instead of using vector subscript I wanted to use iterators. However, when I write up a similar function where I pass an iterator for the first argument and try to return the function with an incremented iterator the loop doesn't stop and I get a segmentation fault. Why is this?</p>
  
  <pre><code>void pvec(std::vector&lt;int&gt;::iterator po, std::vector&lt;int&gt; vec)
  {
      if(po &lt; vec.end()) {
          std::cout &lt;&lt; *po++ &lt;&lt; std::endl;
          return pvec(po,vec);
      }
  }
  </code></pre>
  
  <p>I did try making po a reference and this didn't work either. </p>