In This Chapter
Performing arithmetic operations on character pointers
Examining the relationship between pointers and arrays
Increasing program performance
Extending pointer operations to different pointer types
Explaining the arguments to
main() in our C++ program template
C++ allows the programmer to operate on pointer variables much as she would on simple types of variables. (The concept of pointer variables is introduced in Chapter 8.) How and why this is done along with its implications are the subjects of this chapter.
Some of the same arithmetic operators I cover in Chapter 3 can be applied to pointer types. This section examines the implications of applying these operators to both to pointers and to the array types (I discuss arrays in Chapter 7). Table 9-1 lists the three fundamental operations that are defined on pointers. In Table 9-1, pointer, pointer1, and pointer2 are all of some pointer type, say
char*; and offset is an integer, for example,
long. C++ also supports the other operators related to addition and subtraction, such as
+=., although they are not listed in Table 9-1.
Table 9.1. The Three Basic Operations Defined on Pointer Types
Calculate the address of the object
The opposite of addition
Calculate the number of entries between