This chapter discusses one of the most powerful features of the C++ programming language, the pointer. In Chapter 6, we saw that references can be used to perform pass-by-reference. Pointers also enable pass-by-reference and can be used to create and manipulate dynamic data structures (i.e., data structures that can grow and shrink), such as linked lists, queues, stacks and trees. This chapter explains basic pointer concepts and reinforces the intimate relationship among arrays and pointers. The view of arrays as pointers derives from the C programming language. As we saw in Chapter 7, C++ Standard Library class vector provides an implementation of arrays as full-fledged objects.

Similarly, C++ actually offers two types of stringsstring class objects (which we have been using since Chapter 3) and C-style, char * pointer-based strings. This chapter on pointers discusses char * strings to deepen your knowledge of pointers. In fact, the null-terminated strings that we introduced in Section 7.4 and used in Fig. 7.12 are char * pointer-based strings. This chapter also includes a substantial collection of string-processing exercises that use char *strings. C-style, char * pointer-based strings are widely used in legacy C and C++ systems. So, if you work with legacy C or C++ systems, you may be required to manipulate these char * pointer-based strings.

We will examine the use of pointers with classes in Chapter 13, Object-Oriented Programming: Polymorphism, where we will see that the so-called "polymorphic processing" of object-oriented programming is performed with pointers and references. Chapter 21, Data Structures, presents examples of creating and using dynamic data structures that are implemented with pointers.

C++ How to Program
C++ How to Program (5th Edition)
ISBN: 0131857576
EAN: 2147483647
Year: 2004
Pages: 627
Simiral book on Amazon © 2008-2017.
If you may any questions please contact us: