← All Lessons Lesson 3 / 68
Lesson 3

Meet the Array: A Better Way to Store Many Values

Why We Need Something Better Than Variables

Imagine you want to store the age of every student in a class. With plain variables, you would write one variable for each student:

age1 = 18
age2 = 19
age3 = 17

This works fine for 3 students. But what about 30 students? Or 300? You would have to create 300 separate variables and remember each name. That quickly becomes impossible to manage. We say it does not scale — meaning it does not stay practical as the amount of data grows.

This is exactly the problem an array is built to solve.

What Is an Array?

An array is a single container that can hold many values at once. Think of it like a row of small boxes sitting right next to each other, where each box holds one value.

Here are the key ideas:

  • Contiguous memory — the boxes are placed side by side in the computer's memory, with no gaps. "Contiguous" just means "joined together in a row."
  • Fixed size — in its simplest form, an array is created with a set number of boxes. If you make an array of 7 boxes, it holds 7 values — no more, no less.
  • Same type — every box must hold the same kind of data. An array of numbers holds only numbers; an array of words holds only words. You cannot mix.

So an array looks like one long strip:

| value1 | value2 | value3 | value4 | value5 | value6 | value7 |

The total length of this strip — how many boxes it has — is called its size.

Solving the Student Ages Problem

Now go back to the class of students. Instead of one variable per student, we create one array that holds all the ages together:

| age1 | age2 | age3 | age4 | age5 | age6 | age7 |

One array, one name, and all the ages live inside it. Whether the class has 7 students or 700, we still use a single array. That is the big win: arrays let us handle large amounts of related data without inventing a new variable for every single item.

The Takeaway

An array is a fixed-size, same-type, side-by-side collection of values stored as one unit. It replaces a messy pile of separate variables with one clean, organized container — which is why it is one of the most basic and important building blocks in programming.

Meet the Array: A Better Way to Store Many Values
Diagram — click to zoom (scroll / drag to pan)