Chapter 13. Simple Pointers
The choice of a point of view is the initial act of culture.
There are things and pointers to things. Knowing the difference between the two is very important. This concept is illustrated in Figure 13-1.
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 ...
Get Practical C Programming, 3rd 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.