What is an Array?
Easy+15 XPBefore any algorithm: an array is a row of numbered boxes. Meet the index and the value.
No visualization loaded.
Watch
—
Press Run to begin.
An array is just a row of boxes lined up next to each other. Each box holds one value (a number or a letter), and each box has a position number called its index. The whole point is that the computer can jump to any box instantly if you tell it the index.
▸Why does counting start at 0 and not 1?
The index is really 'how many boxes to skip from the start.' The first box skips 0 boxes, so its index is 0. The second skips 1, so it's index 1, and so on. It feels weird at first, but every box after that lines up perfectly. You'll see it so often it becomes normal.
▸What's the difference between the index and the value?
The index is WHERE the box sits (its position: 0, 1, 2, …). The value is WHAT'S INSIDE the box (like 8 or 3). Two boxes can hold the same value, but no two boxes share the same index — the index is like a house number on a street.
▸Why use a row of boxes instead of just a list in my head?
Because the computer can leap straight to box number 5 without touching boxes 0 through 4. That instant jump is what makes arrays fast, and it's the foundation every search and sort trick is built on.
▸Do all the boxes have to hold the same kind of thing?
In most languages, yes — a whole array is usually all numbers, or all words. Keeping them the same kind is what lets the computer line them up neatly and jump around so quickly.