Problem with temporaries
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/5932239/return-type-in-c">return type in c++</a>  </p>
</blockquote>



<pre><code>#include&lt;iostream&gt;
int&amp; fun();
int main()
{
  int p=fun();
  std::cout&lt;&lt;p;
  return 0;
}

int &amp; fun()
{
  int a=10;
  return  &amp;a;
}
</code></pre>

<p>why does this code give error as,error: <code>invalid initialization of non-const reference of type 'int&amp;' from a temporary of type 'int*'</code>..Actually i am not clear about the temporaries i.e. when are they created and when are they get destroyed.?so ,please explain temporaries to some extent  too.</p>
