Chp9 - C++ PROGRAMMING Chapter 9 References What Is a...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C++ PROGRAMMING Chapter 9 References What Is a Reference? Listing 9.1. Creating and using references. Using the Address of Operator & on References Listing 9.2. Taking the address of a reference Listing 9.3. Assigning to a reference What Can Be Referenced? Listing 9.4. References to objects References Null Pointers and Null References Passing Function Arguments by Reference Listing 9.5. Demonstrating passing by value Making swap() Work with Pointers Listing 9.6. Passing by reference using pointers Implementing swap() with References Listing 9.7. swap() rewritten with references Understanding Function Headers and Prototypes Returning Multiple Values Listing 9.8. Returning values with pointers Returning Values by Reference Listing 9.9. Listing 9.8 rewritten using references. Passing by Reference for Efficiency Listing 9.10. Passing objects by reference Passing a const Pointer Listing 9.11. Passing const pointers References as an Alternative Listing 9.12. Passing references to objects const References When to Use References and When to Use Pointers Mixing References and Pointers Dont Return a Reference to an Object that Isnt in Scope! Listing 9.13. Returning a reference to a non-existent object Returning a Reference to an Object on the Hea Listing 9.14. Memory leaks Pointer, Pointer, Who Has the Pointer? Summary Q&A Quiz , Exercises Chapter 9 References YesterChapter you learned how to use pointers to manipulate objects on the free store and how to refer to those objects indirectly. References, the topic of toChapter's chapter, give you almost all the power of pointers but with a much easier syntax. ToChapter you learn the following What references are. How references differ from pointers. How to create references and use them. What the limitations of references are. How to pass values and objects into and out of functions by reference. What Is a Reference? A reference is an alias; when you create a reference, you initialize it with the name of another object, the target. From that moment on, the reference acts as an alternative name for the target, and anything you do to the reference is really done to the target. You create a reference by writing the type of the target object, followed by the reference operator ( & ), followed by the name of the reference. References can use any legal variable name, but for this guide we'll prefix all reference names with "r." Thus, if you have an integer variable named someInt , you can make a reference to that variable by writing the following: int &rSomeRef = someInt; This is read as " rSomeRef is a reference to an integer that is initialized to refer to someInt ." Listing 9.1 shows how references are created and used....
View Full Document

This note was uploaded on 01/13/2012 for the course CS 131 taught by Professor Clayton during the Spring '08 term at Bethune Cookman.

Page1 / 31

Chp9 - C++ PROGRAMMING Chapter 9 References What Is a...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online