const int &ra=3;
-
As I know, making
raconst will extends the lifetime of the temporary r-value which is in this case 3. This is a little bit confusing, as I knowrashould have the same address as r-value which is here 3, but 3 is not a real variable and it does not have a memory where it’s stored. So how can this be possible? -
what is the difference between:
const int& ra=a;and
int& const ra=a;
Actually a temporary object gets created out of the literal
3, and then that temporary is bound to the const reference. That is how it becomes possible.Now your next question: the difference between these two
is that the second statement is illegal.