References: Exercise 1
Okay, now it’s your turn!
Wait, really? I don’t think I’m ready!
Sure you are! The reason we are teaching you how to draw these diagrams is that they will help you visualize what’s going on.
Follow the rules, and you’ll be able to just look up what value is associated with each name.
Remember: Here are the new diagram rules:
- When a function is called, allocate space for all local variables except references.
- When a reference is initialized, write its name next to its referent.
- When a reference is destroyed, cross out its name (the referent might not be destroyed at the same time!)
Now consider the following code snippet:
int x = 5;
int& z = x;
z = 10;
cout << x << " " << z;
(When logged in, completion status appears here.)