In the C++ primer, I found that const int &
can bind with a int object.I don\'t understand that,because I think const int &
should bind with a
The value of the variable a
which is 0
initially is holded at memory.
If you write later: a=5
, it'll set that value in memory to 5
.
When you write a reference const int & r = a;
you are only saying that r
should access that same place in memory where 5
is being hold.
Because a
is not const
it can modify the value.
This is basically how it works.