Home > Back-end >  A problem about C reference
A problem about C reference

Time:10-03

 

# include
Int & amp; F ()
{
Int I=0;
Int & amp; J=I;
Return j;
}
Int g ()
{
Int j=20;
Return j;
}

Int main (int arg c, char * argv [])
{
Int & amp; Ri=f ();
Int rj=g ();
Printf (" ri=% d \ \ n TRJ=% d ", ri, rj, 6);
Int & amp; Gi=f ();
Int gj=g ();
Printf (" gi=% d \ \ n TGJ=% d ", gi, gj);
return 0;
}
If above procedures section, could you tell me why the first printf buider ri in c + + 6.0=4? thank you

CodePudding user response:

Int & amp; F ()
{
Int I=0;
Int & amp; J=I;
Return j;//retrieves a reference to a local variable, is invalid, caused the outcome of the unknown,
}
Int & amp; Ri=f ();//the ri value here is uncertain, because the reference is invalid,
  • Related