February 2005
Beginner to intermediate
272 pages
4h 53m
English
Pointer arithmetic is straightforward. To understand the nature of pointer arithmetic in C++, it’s best to consider a pointer into an array:
const int MAX = 10;short points[MAX];short *curPoint = points+4;
This gives us an array and a pointer to somewhere near the middle of the array, as shown in Figure 9.
Figure 9. Effect of various arithmetic operations on the address contained in a pointer

If we increment or decrement the pointer curPoint, we are requesting that it point to the next or previous short in the points array. In other words, pointer arithmetic is always scaled in the size of the object that is being ...
Read now
Unlock full access