title: What happens when you pass an expression to a function which has passing by value-result?
body: <p>I'm attending a course of principles of programming languages and there's this exercise where I'm supposed to tell what gets printed by this program:</p>
  
  <pre><code>{
  
  int x=2;
  
  void A (val/res int y) 
  {
      x++; 
      write(y); 
      y=y+2; 
  }
  
  A(x)
  A(x+1)
  write (x); 
  
  }
  
  </code></pre>
  
  <p>A is a function with value/result parameters passing, so right before returning it should copy the final value of its formal parameter (y) in the actual parameter. When A first gets called its actual parameter is x, so there's no problem there. However, the second call to A has x+1 as the actual parameter.
  What does that mean? Maybe the final value of y gets lost because there's no variable where to copy it? Or maybe I should consider it like an equation, so if the final value of y is 7 I get that x + 1 = 7, and then the value of x is 6?</p>