title: Assignement of variable to reference inside a function.
body: <p>I am experimenting with C++ references and came across the following scenario :
  Consider the following code </p>
  
  <pre><code>void foo(float &amp;y)
  {
      float k = 0.0;
      k += 20.1;
      y = k;
      cout &lt;&lt; "y = " &lt;&lt; y &lt;&lt; endl;
  } 
  
  
  
  int main() {
  
      float  i;
      foo(i);
      i+=10.00;
      cout&lt;&lt;"value of I after returning is :: "&lt;&lt;i&lt;&lt;endl;
  
      return 0;
  }
  </code></pre>
  
  <p>The program compiles and runs. The output is :</p>
  
  <pre><code>y = 20.1
  value of i after returning is :: 30.1
  </code></pre>
  
  <p>Now with that happening my dilemma is that ... in function "foo" we assign y (which is a reference to i) as k. And k's scope is only in that function. So once the function returns, k should be destroyed and the value of i should be some undefined value. 
  But contrary to my expectation, i has the value of k after the function. </p>
  
  <p>Am I missing something or understanding things differently ... ? Any help in understanding what is happening here ?
  Thanks in advance. </p>