What is an Array?
An array is a data structure that stores multiple values of the same data type under a single variable name. Each value is accessed by its index (position).
AQA arrays are zero-indexed — the first element is at index 0.
1D Arrays (One-dimensional)
// Declaring a 1D array
scores ← [85, 72, 91, 64, 78]
// Accessing elements — index starts at 0
OUTPUT scores[0] // 85
OUTPUT scores[2] // 91
OUTPUT scores[4] // 78
// Updating an element
scores[1] ← 75 // changes 72 to 75
Traversing an Array with a FOR Loop
// Output all scores
FOR i ← 0 TO 4
OUTPUT scores[i]
ENDFOR
// Find the total
total ← 0
FOR i ← 0 TO 4
total ← total + scores[i]
ENDFOR
OUTPUT total // 390
2D Arrays (Two-dimensional)
A 2D array is like a grid (table) — accessed with two indices: row and column.
// 3x3 grid of integers
grid ← [[1,2,3],[4,5,6],[7,8,9]]
OUTPUT grid[0][0] // 1 (row 0, col 0)
OUTPUT grid[1][2] // 6 (row 1, col 2)
OUTPUT grid[2][1] // 8 (row 2, col 1)
// Traverse entire 2D array
FOR row ← 0 TO 2
FOR col ← 0 TO 2
OUTPUT grid[row][col]
ENDFOR
ENDFOR
Common Array Operations
| Operation | Example |
| Declare | names ← ["Alice","Bob","Carol"] |
| Access | names[0] → "Alice" |
| Update | names[1] ← "Beth" |
| Traverse | FOR i ← 0 TO 2 ... ENDFOR |
| Search | IF scores[i] == target THEN |
Why Use Arrays?
- Store many values of the same type without naming each separately
- Process them efficiently with loops
- Example: storing 30 students' marks — far better than 30 separate variables
Exam tip: AQA arrays start at index 0. For a 5-element array, valid indices are 0–4. The last index = length − 1. Always use a FOR loop from 0 TO length-1 to traverse.
⚠️ Common Mistakes
- Starting the index at 1 instead of 0 — AQA arrays are zero-indexed
- Off-by-one errors: FOR i ← 0 TO 5 on a 5-element array accesses index 5 which doesn't exist
- Confusing row and column order in 2D arrays: grid[row][col]