An array is a data structure that stores multiple values of the same data type under a single identifier. Each value is accessed by its index (position number). Arrays avoid the need to declare many separate variables.
DECLARE scores : ARRAY[1:5] OF INTEGER DECLARE names : ARRAY[1:10] OF STRING
The format is: ARRAY[lower:upper] OF datatype. Cambridge typically uses 1-based indexing in exam questions.
scores[1] ← 72 scores[2] ← 85 OUTPUT scores[3] // outputs the value at index 3
DECLARE scores : ARRAY[1:5] OF INTEGER
FOR i ← 1 TO 5
INPUT scores[i]
NEXT i
FOR i ← 1 TO 5
OUTPUT scores[i]
NEXT i
total ← 0
FOR i ← 1 TO 5
total ← total + scores[i]
NEXT i
average ← total / 5
OUTPUT average
maximum ← scores[1]
FOR i ← 2 TO 5
IF scores[i] > maximum THEN
maximum ← scores[i]
ENDIF
NEXT i
OUTPUT maximum
A 2D array has rows and columns — like a table or grid. Useful for storing grids, timetables, or matrices.
DECLARE grid : ARRAY[1:3, 1:3] OF INTEGER
grid[2, 3] ← 15 // row 2, column 3 OUTPUT grid[1, 1]
FOR row ← 1 TO 3
FOR col ← 1 TO 3
INPUT grid[row, col]
NEXT col
NEXT row
scores[i]4 questions · 11 marks
| Term | Definition |
|---|
10 minutes · mixed marks