References Exercise 3: References to References?
You may be wondering whether you can have a reference to a reference.
That is exactly what I was wondering!
Well, using what we know about references so far, see if you can guess what happens in this example.
Consider the following code snippet:
int m = 7;
int& n = m;
int& o = n;
o = 3;
cout << m << " " << n << " " << o;
Remember, a reference is just another name for its referent.
Okay, now don't worry about right or wrong, just give it some thought!
See? You can't have a reference to a reference.
The variable
n
is just another name form
. So initializingo
withn
is the same as initializingo
withm
. And that means thatn
,m
, ando
are all names for the same piece of data.…what?!?
I guess now you see why there was a video!
(When logged in, completion status appears here.)