Summary

In this hour, you learned what references are and how they compare to pointers. You saw that references must be initialized to refer to an existing object, and cannot be reassigned to refer to anything else. Any action taken on a reference is, in fact, taken on the reference's target object. Proof of this is that taking the address of a reference returns the address of the target.

In this hour you also examined null pointers and null references, and learned why null pointers are useful, but null references are disastrous. You went on to learn about how pass by reference semantics differ from pass by value. Finally, you saw how to use references to return multiple values from function calls.

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.