An array is a data structure that stores multiple values of the same data type under a single variable name. Each value is accessed using an index (position number).
In OCR J277, arrays are zero-indexed — the first element is at index 0, not 1.
Declaring and Initialising Arrays
// 1D array of integers — 5 elements scores = [85, 72, 91, 64, 78]
// 1D array of strings names = ["Alice", "Bob", "Charlie"]
// Accessing elements by index OUTPUT scores[0] // outputs 85 (first element) OUTPUT scores[4] // outputs 78 (last element) OUTPUT names[1] // outputs "Bob"
Array Structure — Visual
Index
0
1
2
3
4
scores
85
72
91
64
78
Key fact: A 5-element array has indices 0, 1, 2, 3, 4. The last valid index is always length - 1.
Modifying Array Elements
// Assigning a new value to an element
scores[2] = 95// changes 91 to 95 at index 2
names[0] = "Anna"// changes "Alice" to "Anna"
Traversing an Array with a FOR Loop
The most common way to process every element in an array is a FOR loop using the index.
// Print all elements FOR i = 0TO4 OUTPUT scores[i] NEXT i
// Find the sum of all elements total = 0 FOR i = 0TO4
total = total + scores[i] NEXT i OUTPUT total
// Find the maximum value maxVal = scores[0] FOR i = 1TO4 IF scores[i] > maxVal THEN
maxVal = scores[i] END IF NEXT i OUTPUT maxVal
2D Arrays
A 2D array is a table (grid) of values, accessed using two indices: array[row][column]. Think of a spreadsheet or seating plan.
// Traverse all elements with nested FOR loops FOR row = 0TO2 FOR col = 0TO2 OUTPUT grid[row][col] NEXT col NEXT row
2D Array — Visual (grid above)
Col 0
Col 1
Col 2
Row 0
1
2
3
Row 1
4
5
6
Row 2
7
8
9
Exam tip: Arrays are almost always tested with FOR loops — know how to traverse, find the sum, find the max/min, and search an array. For a 2D array, always say array[row][column]. OCR J277 arrays are zero-indexed — the first element is [0], not [1]. A common question: "Given array scores = [40,75,90,55,85], what is scores[2]?" — answer is 90 (index 2 = third element).
⚠️ Common Mistakes
Starting the index at 1 instead of 0 — arrays in OCR J277 are zero-indexed
Accessing scores[5] in a 5-element array — valid indices are 0–4; index 5 is out of bounds
Storing different data types in one array — arrays hold values of the same type
In 2D arrays, confusing row and column: grid[row][column] not grid[column][row]
Forgetting to iterate from 0, not 1: FOR i = 0 TO length-1
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
Worksheet — 2.2.1d Arrays
8 questions · 20 marks
Q1Define what an array is and state two properties of an array.[3]
✅ Mark scheme
An array is a data structure that stores multiple values under a single variable name [1]. Properties (any 2): all elements are the same data type [1]; elements are accessed using an index [1]; arrays are zero-indexed in OCR J277 (first element at index 0) [1]; arrays have a fixed size [1].
Q2Given: grades = ["A","B","C","D","E"]. What is the value of grades[2]? What is the index of "E"?[2]
✅ Mark scheme
grades[2] = "C" [1] (zero-indexed: A=0, B=1, C=2). The index of "E" is 4 [1].
Q3Write pseudocode to declare an array called temps with values 12, 15, 9, 18, 21, then output all values using a FOR loop.[3]
✅ Mark scheme
temps = [12,15,9,18,21] [1]; FOR i = 0 TO 4 [1]; OUTPUT temps[i]; NEXT i [1]. Award marks for correct declaration, correct loop bounds (0 to 4), and access with index.
Q4Write pseudocode to calculate and output the total of all values in the array scores = [40, 75, 90, 55, 85].[3]
✅ Mark scheme
scores = [40,75,90,55,85]; total = 0 [1]; FOR i = 0 TO 4; total = total + scores[i] [1]; NEXT i; OUTPUT total [1]. Answer: total = 345.
Q5Explain what a 2D array is and give an example of when you might use one.[2]
✅ Mark scheme
A 2D array is a grid/table of values accessed using two indices [row][column] [1]. Example: storing a seating plan, a grid for a game (e.g. noughts and crosses), a timetable, or marks for multiple students across multiple tests [1].
Q6Given grid = [[5,10,15],[20,25,30]], what is the value of grid[1][2]?[1]
✅ Mark scheme
30 [1]. Row 1 = [20,25,30]. Column 2 = 30.
Q7Write pseudocode to find and output the largest value in nums = [34, 17, 58, 42, 9].[4]
✅ Mark scheme
nums = [34,17,58,42,9] [½]; maxVal = nums[0] [1]; FOR i = 1 TO 4 [1]; IF nums[i] > maxVal THEN maxVal = nums[i]; END IF [1]; NEXT i; OUTPUT maxVal [½]. Answer: 58.
Q8State one advantage of using an array over separate variables to store 100 student scores.[2]
✅ Mark scheme
Any one with explanation: you only need one variable name instead of 100 (score1, score2... score100) [1]; you can process all values with a single FOR loop rather than 100 separate lines [1]; code is shorter, easier to read and maintain [1].
?
out of 20 — self-mark above
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 8
Click to reveal definition
🎉
Complete!
Term
Definition
🎯
Mini Test — 2.2.1d Arrays
10 questions · 10 marks · 10 minutes
⏱ 10:00
10 marks
Section A — Multiple Choice [5 marks]
Q1Given nums = [10, 20, 30, 40, 50], what is nums[3]?
Q2An array has 6 elements. What is the index of the last element?
Q3Which of these correctly accesses row 2, column 1 of a 2D array called grid?
Q4What data types can be stored in a single array?
Q5scores = [40,75,90,55,85]. After scores[1] = 80, what is scores[1]?
Section B — Short Answer [5 marks]
Q6What is an array? State two features that distinguish it from a regular variable.
Mark schemeAn array stores multiple values under one variable name [1]. Features: all elements are the same data type [1]; elements accessed by index (position) [1]; zero-indexed in OCR J277 [1].
Q7Write pseudocode to find the minimum (smallest) value in the array prices = [4.99, 1.50, 8.75, 2.30, 6.00].
Mark schememinVal = prices[0] [1]; FOR i = 1 TO 4 [1]; IF prices[i] < minVal THEN minVal = prices[i]; END IF; NEXT i [1]; OUTPUT minVal. Answer: 1.50.
Q8grid = [[1,2],[3,4],[5,6]]. State the values of grid[0][1] and grid[2][0].
Mark schemegrid[0][1] = 2 [1] (row 0 is [1,2], column 1 = 2). grid[2][0] = 5 [1] (row 2 is [5,6], column 0 = 5).
Q9Give one reason why using an array is better than using separate variables for 50 student scores.
Mark schemeAny valid reason: one variable name instead of 50 [1]; can loop through all elements with one FOR loop instead of 50 separate lines [1]; easier to read and maintain [1].
Q10Explain what 'index out of bounds' means in the context of arrays.
Mark schemeAccessing an array element using an index that does not exist [1]. E.g. accessing index 5 in a 5-element array (valid indices: 0–4). Causes a runtime error — the program crashes [1].