title: unable to predict the output when a function returning reference is written on LHS
body: <p>I know following about reference</p>
  
  <p>eg. <code>int &amp;ref=x;</code>
  then ref and x are the names of same locations in memory.
  Memory is not allocated for reference unlike pointers.</p>
  
  <p>I was writting a simple swap program in C++ using references which I successfully wrote.</p>
  
  <p>Then i decided to try out what happens when a function which returns reference is LHS of an expression and now I am unable to predict the output of the below code.</p>
  
  <pre><code>#include&lt;iostream.h&gt;
  
  int &amp;  swap(int &amp;,int &amp;);   //function returns reference
  void main()
  {
      int x=10,y=20;
      int &amp;ref1=x,&amp;ref2=y;
      swap(ref1,ref2)=x;         //what happens here?
      cout&lt;&lt;x&lt;&lt;y;
  }
  
  int &amp; swap(int &amp;ref1,int &amp;ref2)
  {
      int temp;         
      temp=ref1;        //swap   
      ref1=ref2;        //code
      ref2=temp;        //here
  
      return ref2;      //tried out this(has nothing to do with swapping)
  }
  </code></pre>
  
  <p>O/P 20 20</p>