O'Reilly logo

Practical C Programming, 3rd Edition by Steve Oualline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Simple Pointers

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

José Ortega y Gasset

There are things and pointers to things. Knowing the difference between the two is very important. This concept is illustrated in Figure 13-1.

A thing and a pointer to a thing
Figure 13-1. A thing and a pointer to a thing

In this book, we use a box to represent a thing. The name of the variable is written on the bottom of the box. In this case, our variable is named thing. The value of the variable is 6.

The address of thing is 0x1000. Addresses are automatically assigned by the C compiler to every variable. Normally, you don’t have to worry about the addresses of variables, but you should understand that they’re there.

Our pointer (thing_ptr) points to the variable thing. Pointers are also called address variables because they contain the addresses of other variables. In this case, our pointer contains the address 0x1000. Because this is the address of thing, we say that thing_ptr points to thing.

Variables and pointers are much like street addresses and houses. For example, your address might be “214 Green Hill Lane.” Houses come in many different shapes and sizes. Addresses are approximately the same size (street, city, state, and zip). So, while “1600 Pennsylvania Ave.” might point to a very big white house and “8347 Undersea Street” might be a one-room shack, both addresses are the same size.

The same is true ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required