Skip to Main Content
Practical C++ Programming, 2nd Edition
book

Practical C++ Programming, 2nd Edition

by Steve Oualline
December 2002
Beginner to intermediate content levelBeginner to intermediate
576 pages
14h 6m
English
O'Reilly Media, Inc.
Content preview from Practical C++ Programming, 2nd Edition

Chapter 15. Simple Pointers

The choice of a point of view is the initial act of culture.

Ortega y Gasset

There are things, and there are pointers to things (Figure 15-1).

A thing and a pointer to a thing

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 address ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Discovering Modern C++, 2nd Edition

Discovering Modern C++, 2nd Edition

Peter Gottschling

Publisher Resources

ISBN: 0596004192Supplemental ContentErrata Page