8.1. Introduction

This chapter discusses pointers—one of the most powerful, yet challenging to use, C++ capabilities. Our goals here are to help you determine when it’s appropriate to use pointers, and show how to use them correctly and responsibly.

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 that can grow and shrink, such as linked lists, queues, stacks and trees. This chapter explains basic pointer concepts.

We also show the intimate relationship among built-in arrays and pointers. C++ inherited built-in arrays from the C programming language. As we saw in Chapter 7, the C++ Standard Library classes array and vector provide implementations of arrays as full-fledged objects—in fact, array and vector each store their elements in built-in arrays. In new software development projects, you should favor array and vector objects to built-in arrays.

Similarly, C++ actually offers two types of strings—string class objects (which we’ve been using since Chapter 3) and C-style, pointer-based strings (C strings). This chapter briefly introduces C strings to deepen your knowledge of pointers and built-in arrays. C strings were widely used in older C and C++ software. We discuss C strings in depth in Appendix F. In new software development projects, you should favor string class objects.

We’ll examine the use of pointers with class objects in Chapter 12, where we’ll see that the so-called “polymorphic processing” associated with object-oriented programming is performed with pointers and references.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.200.232