1D Arrays

Lesson 7 of 20

One name, many values: reserve a row of score cells, index them from 0 and let a for loop walk and sum them.

The big picture

A row of boxes, one name

An array stores many values of the same type side by side — and loops know exactly how to walk it.

One name, many cells

int scores[3]; reserves three int boxes glued side by side under one name.

Indexing starts at 0

scores[0] is the first cell, scores[2] the last — valid indexes run 0 .. size - 1.

Read and write

scores[1] = 6 stores a value; scores[1] reads it — brackets work both ways.

Loops love arrays

for (int i = 0; i < 3; i++) visits every cell — the counter is the index.

Fixed size

An array never grows. Plan the size up front — vector comes later in the course.