const int &ra=3;
As I know, making ra
const will extends the lifetime of the temporary r-value which is in this case 3. This is a little bit confusing, as I know ra
should 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;
but 3 is not a real variable and it does not have a memory where it's stored. so how can this be possible ?
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
const int& ra=a;
int& const ra=a;
is that the second statement is illegal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With