Returning a reference can work?
<p>I used to think returning a reference is bad as our returned reference will refer to some garbage value. But this code works (<code>matrix</code> is a class):</p>

<pre><code>const int max_matrix_temp = 7;
matrix&amp;get_matrix_temp()    
{
   static int nbuf = 0;  
   static matrix buf[max_matrix_temp];  

   if(nbuf == max_matrix_temp)    
      nbuf = 0;  

   return buf[nbuf++];
} 

matrix&amp; operator+(const matrix&amp;arg1, const matrix&amp;arg2)
{  
    matrix&amp; res = get_matrix_temp();
    //...  
    return res;
}
</code></pre>

<p>What is <code>buf</code> doing here and how does it save us from having garbage values?</p>
