title: How does c++ by-ref argument passing is compiled in assembly?
body: <p>In the late years of college, I had a course on Compilers. We created a compiler for a subset of C. I have always wondered how a pass-by-ref function call is compiled into assembly in C++.</p>
  
  <p>For what I remember, a pass-by-val function call follows the following procedure:</p>
  
  <ul>
  <li>Store the address of the PP</li>
  <li>Push the arguments onto the stack</li>
  <li>Perform the function call</li>
  <li>In the function, pop from stack the parameters</li>
  </ul>
  
  <p>What's different for pass-by-reference? (int void(int&amp;);)</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I may sound totally lost but, if you could help me I'd really appreciate it.</p>
  
  <p>Everyone's answer is basically that it passes the address instead of the value. I understood that to be basically what passing a pointer is. So how come, these two functions, behave differently?:</p>
  
  <pre><code>struct A {
      int x;
      A(int v){
          x = v;
      }
  };
  
  int byRef(A&amp; v){
      v = A(3);
      return 0;
  }
  
  int byP   (A* v){
      v = &amp;A(4); //OR new A(4)
      return 0;
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      A a (1); A b (2);
      byRef(a); byP  (&amp;b);
      cout &lt;&lt; a.x &lt;&lt; " " &lt;&lt; b.x;
  
      system("pause");
  
      return 0;
  }
  </code></pre>
  
  <p>I know that in byP(A*), v is being passed by value, thus, it won't affect the caller's argument. Then, how would you implement byRef(A&amp;) in terms of A*?</p>