Chp8 - C PROGRAMMING Chapter 8 Pointers What Is a Pointer...

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

View Full Document Right Arrow Icon
C++ PROGRAMMING Chapter 8 Pointers What Is a Pointer? Figure 8.1. Listing 8.1. Demonstrating address of variables Figure 8.2. Storing the Address in a Pointer Pointer Names The Indirection Operator Pointers, Addresses, and Variables Figure 8.3. Manipulating Data by Using Pointers Listing 8.2. Manipulating data by using pointers Examining the Address Listing 8.3. Finding out what is stored in pointers Pointers Why Would You Use Pointers? The Stack and the Free Store new delete Listing 8.4. Allocating, using, and deleting pointers. Memory Leaks Creating Objects on the Free Store Deleting Objects Listing 8.5. Creating and deleting objects on the free store Accessing Data Members Listing 8.6. Accessing member data of objects on the free store. Member Data on the Free Store Listing 8.7. Pointers as member data The this Pointer Listing 8.8. Using the this pointer Stray or Dangling Pointers Listing 8.9. Creating a stray pointer const Pointers const Pointers and const Member Functions Listing 8.10. Using pointers to const objects const this Pointers Summary Quiz , Exercises
Background image of page 1

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

View Full DocumentRight Arrow Icon
Chapter 8 Pointers One of the most powerful tools available to a C++ programmer is the ability to manipulate computer memory directly by using pointers. ToChapter you will learn What pointers are. How to declare and use pointers. What the free store is and how to manipulate memory. Pointers present two special challenges when learning C++: They can be somewhat confusing, and it isn't immediately obvious why they are needed. This chapter explains how pointers work, step by step. You will fully understand the need for pointers, however, only as the guide progresses. What Is a Pointer? New Term: A pointer is a variable that holds a memory address. To understand pointers, you must know a little about computer memory. Computer memory is divided into sequentially numbered memory locations. Each variable is located at a unique location in memory, known as its address. (This is discussed in the "Extra Credit" section following Chapter 5, "Functions.") Figure 8.1 shows a schematic representation of the storage of an unsigned long integer variable theAge . Figure 8.1. A schematic representation of theAge . Different computers number this memory using different, complex schemes. Usually programmers don't need to know the particular address of any given variable, because the compiler handles the details. If you want this information, though, you can use the address of operator ( ), which is illustrated in Listing 8.1. Listing 8.1. Demonstrating address of variables. 1:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the 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 / 27

Chp8 - C PROGRAMMING Chapter 8 Pointers What Is a Pointer...

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