Chapter 15. Simple Pointers
The choice of a point of view is the initial act of culture.
There are things, and there are pointers to things (Figure 15-1).
Figure 15-1. A thing and a pointer to a thing
Things can come in any size; some may be big, some may be small. Pointers come in only one size (relatively small).
Throughout this book I use a box to represent a thing. The box may be large or small, but things are always a box. Pointers are represented by arrows.
Most novice programmers get pointers and their contents confused.
To limit this problem, all pointer variables in this book end with the
extension _ptr
. You probably want to follow this convention in your own
programs. Although not as common as it should be, this notation is
extremely useful.
Figure 15-1 shows one
thing: a variable named thing
. The
name of the variable is written on the box that represents it. This
variable contains the value 6. The actual address of this variable is 0x1000. C++
automatically assigns an address to each variable at compile time. The
actual addresses differ from machine to machine. Most of the time you
donât have to worry about variable addresses, as the compiler takes care
of that detail. (After all, youâve gotten through 14 chapters of
programming without knowing anything about addresses.)
The pointer (thing_ptr
) points
to the variable thing
. Pointers are also called ...
Get Practical C++ Programming, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.