An array stores many values of the same type side by side — and loops know exactly how to walk it.
1 One name, many cells
int scores[3]; reserves three int boxes glued side by side under one name.
2 Indexing starts at 0
scores[0] is the first cell, scores[2] the last — valid indexes run 0 .. size - 1.
3 Read and write
scores[1] = 6 stores a value; scores[1] reads it — brackets work both ways.
4 Loops love arrays
for (int i = 0; i < 3; i++) visits every cell — the counter is the index.
5 Fixed size
An array never grows. Plan the size up front — vector comes later in the course.
A row of boxes, one name
One name, many cells1int scores[3]; reserves three int boxes glued side by side under one name. Indexing starts at 02scores[0] is the first cell, scores[2] the last — valid indexes run 0 .. size - 1.
Read and write3scores[1] = 6 stores a value; scores[1] reads it — brackets work both ways. Loops love arrays4for (int i = 0; i < 3; i++) visits every cell — the counter is the index. Fixed size5An array never grows. Plan the size up front — vector comes later in the course. 5 building blocks make up A row of boxes, one name
An array is one contiguous strip of cells — press Run to walk it cell by cell.
Press play — three writes fill the array, then a loop visits every cell for the total.
mainThe OS calls main() — execution begins.
Memory
no variables yet — press play
Console
output appears as the program runs…
Searching for 9: two decisions per cell — is the index still valid, and does the cell match?
process decision input / output start / end An initializer list, one overwrite, three prints — trace the cells.
Your predicted output — one line per console line
Hint: The initializer fills {2, 4, 6}; then a[1] is overwritten with a[0] + a[2] = 8.
01An array is a fixed row of same-type cells under one name.
02Indexing starts at 0 — the last valid index is size - 1.
03C++ does not check indexes: a[5] on a 3-cell array is your bug to find.
04Pair arrays with for loops — the counter is the index.