1D Arrays

Lesson 7 of 20

One name, many boxes: store a row of values, index any of them, and never forget that counting starts at 0.

The big picture

A row of numbered boxes

An array stores many values under one name, side by side in memory. Each box gets an index — and counting starts at zero.

Declaration

int a[5] reserves five int boxes in one unbroken block of memory.

Indexing

a[0] is the first box and a[4] the last — valid indexes run from 0 to size - 1.

Initializer

int a[3] = {7, 8, 9} fills all three boxes right at declaration.

No guard rails

C never checks your index. a[5] on a size-5 array reads past the end silently.