Home > Back-end >  Returns a reference type C doubts to reference types or not familiar with
Returns a reference type C doubts to reference types or not familiar with

Time:11-19

#include
using namespace std;
Int & amp; Fun1 ()
{int a;
return a;
}
Int & amp; Fun2 (int a)
{
Return a + 1;
}
Int main () {
Fun1 ()=5;
CoutInt b=2;
Fun2 (b) +=2;
Coutreturn 0;
}
Ask these two functions respectively what problems?

CodePudding user response:

Error is returned to a local variable references, and retrieves a reference to a temporary variable

CodePudding user response:

Fun1 retrieves a reference to a local variable, function, a local variable release, reference is unclear; If fun2 function parameters and reference; Int & amp; Fun2 (int & amp; a)
  • Related