What is an array?
Imagine storing five student scores. Instead of five separate variables, an array stores related elements of the same data type under one identifier. Each element is accessed using an index.
Cambridge syllabus focus
Topic 8 programming: declare and use one- and two-dimensional arrays, store and retrieve elements, and process arrays using iteration. Follow the bounds given in each question.
1D arrays — one index
A 1D array resembles a row of numbered pigeonholes. Here Score contains five integer values, indexed from 1 to 5.
| Index | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|
| Score | 72 | 65 | 81 | 54 | 90 |
Score[3] selects the element at index 3, which contains 81. The number in square brackets identifies a position, not the stored value.
Declaring and filling a 1D array
A declaration specifies the array bounds and data type. Assignment stores a value at a selected index.
Output: 81. Assigning a new value to Score[3] changes that element only.
Check your understanding 1
What is Score[4]?
Reveal answer
54, the element stored at index 4.
2D arrays — two indexes
A 2D array is a grid. The first index can identify the row and the second the column. In this example Mark[2,1] means row 2, column 1.
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | 72 | 68 | 75 |
| Row 2 | 81 | 77 | 89 |
Output: 89. Row 2, column 3 contains 89.
Check your understanding 2
Which element contains 68, and what is Mark[2,2]?
Reveal answer
Mark[1,2] contains 68; Mark[2,2] contains 77.
Using a FOR loop to total a 1D array
A loop can visit each element in turn. Initialise the total to zero before adding the scores.
| Index | Score[Index] | Running total |
|---|---|---|
| 1 | 72 | 72 |
| 2 | 65 | 137 |
| 3 | 81 | 218 |
| 4 | 54 | 272 |
| 5 | 90 | 362 |
The final output is 362. The trace table records the total after every iteration.
Nested loops for a 2D array
Use an outer loop for rows and an inner loop for columns. The inner loop completes all columns before the next row begins.
Output order: 72, 68, 75, 81, 77, 89. The nested loops output 2 × 3 = 6 elements.
Check your understanding 3
How many times does OUTPUT run in the nested loops?
Reveal answer
Six times: two rows multiplied by three columns.
1D and 2D arrays compared
| Feature | 1D array | 2D array |
|---|---|---|
| Structure | Line of elements | Grid of elements |
| Indexes | One | Two |
| Example | Score[3] | Mark[2,3] |
| Typical processing | One loop | Nested loops |
Common Cambridge exam mistakes
Score[3] selects the third element; it does not mean the value 3.
Read the declared bounds. Arrays do not always start at index 0.
A 2D array needs both row and column indexes.
Set Total ← 0 before accumulating values.
For indexes 1–5, index 6 is invalid.
Exam focus — original FutureLogic practice
Original Cambridge-style practice questions, not official examination questions. Suggested marks are indicative; actual mark schemes determine credit.
Question 1 (2 marks)
State two differences between 1D and 2D arrays.
Reveal model answer
A 1D array uses one index and resembles a line; a 2D array uses two indexes and resembles a grid.
Question 2 (3 marks)
Declare an INTEGER array Age with indexes 1 to 20 and store 16 at index 4.
Reveal model answer
DECLARE Age : ARRAY[1:20] OF INTEGER and Age[4] ← 16.
Question 3 (3 marks)
Write pseudocode to output all five elements of Score.
Reveal model answer
FOR Index ← 1 TO 5, then OUTPUT Score[Index], then NEXT Index.
Question 4 (4 marks)
Describe how nested loops output a 3-row, 4-column array.
Reveal model answer
Use an outer loop for rows 1–3 and an inner loop for columns 1–4; output the element at each row and column. There are 12 outputs.
Quick quiz
- What is an array element?
- What does an index identify?
- How many indexes select a 2D element?
- What is Score[5]?
- Why are loops useful with arrays?
- What does out of bounds mean?
Quiz answers
Reveal all answers
- One stored value.
- An element position.
- Two.
- 90.
- They process many elements efficiently.
- An index outside the valid range.
Final summary
Array
Multiple same-type values under one identifier.
Index
Selects one element.
1D
One index.
2D
Two indexes.
Loops
Process elements.
Bounds
Specify valid indexes.