title: C++ - passing parameter by reference in a function which returns int
body: <p>I have created a C++ program in order to test the functionality of passing parameters by reference for functions.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int f(int &amp;b) {
      b = b + 1;
      cout &lt;&lt; b &lt;&lt; endl;
      return b;
  }
  
  int main() {
      int t = 10;
  
      cout &lt;&lt; f(t) &lt;&lt; " " &lt;&lt; t &lt;&lt; endl;
      //cout &lt;&lt; f(&amp;t) &lt;&lt; " " &lt;&lt; t &lt;&lt; endl;
  
      system("PAUSE");
  
      return 0;
  }
  </code></pre>
  
  <p>Could you please explain to me why does this program won't affect the value of <code>t</code> after the execution of the <code>f</code> function? The <code>b</code> parameter in passed be reference, so I thought that it's value would change after the execution of the program because I am working with the actual variable from the main function, not a copy of it. In this case, I would expect it to be 11, but it's not affected by the execution of the program.</p>
  
  <p>Why is this happening?</p>