title: What is happening in this fuction?
body: <pre class="lang-cpp prettyprint-override"><code>#include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  int print_vector(vector&lt;int&gt; &amp;data) {
      int size = data.size();
      cout&lt;&lt; &quot;size &quot; &lt;&lt; size &lt;&lt; endl;
      for(int i = 0;i &lt; size;i++) {
          if(data[i] == 3) {
              return i;
          }
          cout&lt;&lt; data[i] &lt;&lt; endl;
      }
      cout&lt;&lt; &quot;Hello!&quot; &lt;&lt; endl;
      return data.size() - 1;
  }
  
  int main() {
      vector&lt;int&gt; data = {1,2,3,4,5};
      
      cout&lt;&lt;  print_vector(data) &lt;&lt; endl;
  }
  </code></pre>
  <p>When I run my code, once it reaches my <code>if</code> statement, it returns <code>i</code> and then returns <code>data.size()</code> which is only 2, and if I do <code>data.size() -1</code> it is still 2.</p>
  <p>Why does this happen? Can anybody help?</p>