In the “C++ programming language”, there is an example
void g()
{
int ii = 0;
int& rr = ii;
rr++;
int* pp = &rr;
}
The author states:
This is legal, but rr++ does not increment the reference rr, rather, ++ is applied to an int that happens to be ii.
I am quite confusing about this statement, why “rr++ does not increment the reference rr”? So rr is just used as “bridge” to increment ii?
A reference is similar to a dereferenced pointer to a variable. For example:
In this example, both statements will set v to 4.