by Joe Pardue
Follow along with this
series! Joe’s book & kits
are available at
Discuss this article in the
Nuts & Volts forums at
Last month, we finished up with C pointers (whew!)
and we built a chaser light marquee frame using the
Simple Chaser Lights kit available from Nuts & Volts. This
month, we will study a C topic related to pointers: arrays.
As a reward for our patience with the theory, we will build
another project using the chaser lights kit: a POV
(Persistence Of Vision) wand.
As before, this Workshop is split between some C
theory and a tangentially related (but more fun) lab
exercise that uses LEDs. We are nearing the end of the C
theory, and soon will just use it and refer back to these
articles when we show the C code. So, save your back
issues! They might come in handy some day when you
need a refresher on some arcane C concept.
Figure 1 shows the chaser lights board tied down on
a stick and swung madly about in a dark room where you
can just see NUTS & VOLTS spelled out in the air. In the
lab section this month, we will look at some of the
principles behind the phenomenon of POV and will build
the actual thing next month.
Last month, you probably got good and sick of
hearing about pointers. I hope that you also got how
they work, because they are critical to serious use of
the C programming language. After all that, we are now
going to look at arrays that do many of the same things
you’d do with pointers, but are a lot easier to
understand. You might wonder why we didn’t look at
arrays first if they are easier. The reason is
that you’d tend to skim over pointers if
you learned arrays first. You’d think, ‘Oh I
can do that with arrays, no need to learn
pointers!’ Well, not exactly. Pointers and
arrays are very closely related but not
identical, and you will run into pointers a
lot in C, so best learn them now rather
than when your boss is standing over you
with a whip.
■ FIGURE 1. Slinging the simple chaser lights board.
An array is a C data type that
represents a sequence of memory
locations. Think about that for a moment.
Memory is where data is located and each
of these locations has an address
beginning at 0 and increasing all the way
to the end of memory (okay, there are
exceptions but they are not relevant here).
When you create an array of size x, C will
assign x contiguous locations in memory
to that array. Say, for instance, you create