Step 59. Pointers 2: Arrays — The Law of Adjacent Slots
Level 1 — Programming and the Computer’s Inner Workings | Difficulty ★★★★☆ | Estimated time: 4 hours
Prerequisites: Steps 56–58 complete. You’ve done the basic experiments with pointers (& and *).
- What you need: a Linux terminal, gcc, a notebook for writing down addresses.
- Caution: today’s exercises are experiments inside your own computer, so they’re safe. Addresses change on every run — numbers differing from the book is normal.
In Step 58 we looked at the slot of a single variable. Today we look at five slots at once: the array — several variables of the same kind lined up in a row. It looks similar to a Python list, but inside it’s far simpler, and for that reason it shows you far more.
Today’s topic in one sentence: "arrays and pointers are actually the same thing." This sentence is C’s most famous truth, and at first the hardest one to believe. So today we go by experiment, not persuasion. Print addresses, add to them, follow them — and you’ll believe it on your own. And when this truth meets the tiny guard hiding at the end of strings,