title: Use of reference variables in C++
body: <p>I came across the following question:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int f(int &amp;x, int c)
  {
      c  = c - 1;
      if (c == 0) return 1;
      x = x + 1;
      return f(x, c) * x;
  }
  int main()
  {
      int p = 5;
      printf(&quot;%d&quot;, f(p, p));
  }
  </code></pre>
  <p>As far as I have worked out, the recursion calls should work, and with each recursion call, value of c should reduce by 1 and value of x should increase by 1 . However, if I calculate it that way, the answer comes out to be 3024. However, on executing, the output comes out to be 6561. I am not really sure how this answer is coming.</p>
  <p>I have the link to the article from where this question is taken, but I fail to understand how x will remain constant as is described in this link: <a href="https://www.geeksforgeeks.org/c-references-question-1/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/c-references-question-1/</a></p>
  <p>Can someone help me with the working behind this code?</p>