{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern