OCR · GCSE · Computer Science
Course version: J277 · Version from Sept 2022
The use of arrays (or equivalent) when solving problems, including both…
Full specification wording
Additional programming techniques: The use of arrays (or equivalent) when solving problems, including both one-dimensional (1D) and two-dimensional arrays (2D)
An array stores several values of the same data type under one identifier, each reached by an index.
Checked against the OCR J277 specification on .
- Point 5 of 7
- 4 key terms
Study notes
From the checked teaching notes for this specification point.
The idea
An array stores several values of the same data type under one identifier, each reached by an index. A 1D array is a single list, such as scores[0] to scores[4] holding five test marks. A 2D array is a table of rows and columns, such as grid[2][3], where the first index selects the row and the second the column. You use arrays to avoid many separate variables, to loop through data with a counter, and to store grids for games or tables of records. You must be able to declare an array, assign and read elements, traverse it with a for loop, and process every element, for example totalling a 1D array or searching a 2D array row by row.
What earns the marks
- Declares an array of a stated size and data type, for example scores as five integers, and explains that all elements share one identifier.
- Reads and writes individual elements using correct indices, remembering that indexing commonly starts at 0 so the last index is size − 1.
- Traverses a 1D array with a for loop whose counter runs from the first to the last valid index, processing each element once.
- Uses two indices for a 2D array, the first for the row and the second for the column, and nests two loops to visit every cell.
- Applies standard array processing such as finding a total, maximum or minimum, or searching for a value and recording its position.
- Chooses an array over separate variables when several related values of the same type must be stored and processed together.
Common mistakes and how to put them right
Using an index equal to the array length, for example scores[5] on a five-element array.
Put it right: The error is an out-of-range access, so the correction is to loop while the counter is less than the length.
Swapping the row and column indices in a 2D array.
Put it right: The error is reading the wrong cell, so the correction is to fix the convention that the first index is the row and the second is the column.
Mixing data types in one array, such as names and ages together.
Put it right: The error breaks the same-type rule, so the correction is to use separate arrays or a record structure.
Exam tips
- Sketch the array as boxes with their index numbers before writing code, and mark the first and last valid indices.
- For a 2D array, label the rows and columns on your sketch and trace one complete inner loop before writing the nested loops.
- Check every loop bound against the declared size, since off-by-one errors are the most common lost mark in array questions.
Try the lesson
The start of the Additional programming techniques: The use of arrays (or equivalent) when solving problems, including both one-dimensional (1D) and two-dimensional arrays (2D) lesson, made from checked teaching notes for this specification point.
Have a go first
Which statement best describes a one-dimensional (1D) array?
Listen
An array stores several values of the same data type under one identifier, each reached by an index. A 1D array is a single list, such as scores[0] to scores[4] holding five test marks. A 2D array is a table of rows and columns, such as grid[2][3], where the first index selects the row and the second the column. You use arrays to avoid many separate variables, to loop through data with a counter, and to store grids for games or tables of records. You must be able to declare an array, assign and read elements, traverse it with a for loop, and process every element, for example totalling a 1D array or searching a 2D array row by row. A strong answer earns marks for these points. Declares an array of a stated size and data type, for example scores as five integers, and explains that all elements share one identifier. Reads and writes individual elements using correct indices, remembering that indexing commonly starts at 0 so the last index is size − 1. Traverses a 1D array with a for loop whose counter runs from the first to the last valid index, processing each element once. Uses two indices for a 2D array, the first for the row and the second for the column, and nests two loops to visit every cell. Exam tip: Sketch the array as boxes with their index numbers before writing code, and mark the first and last valid indices.
Key words
Say what each word means before you turn the card.
Array
Try answering aloud or in your head before turning the card.
1D array
Try answering aloud or in your head before turning the card.
2D array
Try answering aloud or in your head before turning the card.
Index
Try answering aloud or in your head before turning the card.
See every definition
- Array
- Stores several values of the same data type under one identifier, with each value reached by an index.
- 1D array
- A single list, such as scores[0] to scores[4] holding five test marks.
- 2D array
- A table of rows and columns, such as grid[2][3], where the first index selects the row and the second the column.
- Index
- The value used to reach an element in an array, commonly starting at 0 so the last index is size − 1.
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of Additional programming techniques: The use of arrays (or equivalent) when solving problems, including both one-dimensional (1D) and two-dimensional arrays (2D)
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge