In this guide:
Exam Strategy: 1-Based Indexing
The single most common mistake students make with arrays in Cambridge computer science exams is getting the index numbers wrong. In almost all modern programming languages, arrays start at index 0. However, in standard Cambridge Pseudocode, arrays traditionally start at index 1. You must state the upper and lower bounds clearly when declaring an array.
Python vs. Pseudocode Arrays
Python doesn't technically have built-in arrays; it uses dynamic "Lists" that can shrink, grow, and hold mixed data types. Pseudocode arrays are static (fixed size) and homogeneous (hold only one data type).
| Concept | 🐍 Python (Wrong for Exams) | 📘 Cambridge Pseudocode (Correct) |
|---|---|---|
| Declaration | scores = [] | DECLARE Scores : ARRAY[1:5] OF INTEGER |
| First Element | scores[0] = 10 | Scores[1] ← 10 |
| Adding Data | scores.append(50) | Must assign to a specific index: Scores[2] ← 50 |
1. 1D Arrays (Lists)
A 1-Dimensional array is like a single row of lockers. When you declare it in standard pseudocode, you must specify the lower bound, the upper bound, and the data type.
// Declare an array that holds 5 integers, indexed 1 to 5
DECLARE Scores : ARRAY[1:5] OF INTEGER
// Assigning data to specific indexes
Scores[1] ← 95
Scores[2] ← 82
Scores[5] ← 100
// Retrieving data
OUTPUT "The first score is: ", Scores[1]
2. Traversing a 1D Array
The true power of arrays comes from combining them with FOR loops. Instead of writing out an operation for every single index, you can use the loop's counter variable to scan through the entire array automatically.
DECLARE Names : ARRAY[1:3] OF STRING
DECLARE i : INTEGER
Names[1] ← "Alice"
Names[2] ← "Bob"
Names[3] ← "Charlie"
// The loop variable 'i' acts as the index!
FOR i ← 1 TO 3
OUTPUT "Student ", i, " is ", Names[i]
NEXT i
3. 2D Arrays (Grids)
If a 1D array is a row, a 2D array is a grid (like a spreadsheet or a chessboard). You declare it by providing the bounds for the Rows first, followed by the Columns.
// A grid with 3 rows and 3 columns
DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
// Place an 'X' in Row 1, Column 1
Board[1, 1] ← 'X'
// Place an 'O' in Row 2, Column 3
Board[2, 3] ← 'O'
4. Traversing a 2D Array (Nested Loops)
To search through a 2D array, you must use nested loops. The outer loop usually moves down the rows, while the inner loop moves across the columns.
DECLARE r : INTEGER
DECLARE c : INTEGER
// Loop through rows 1 to 3
FOR r ← 1 TO 3
// Loop through columns 1 to 3 inside that row
FOR c ← 1 TO 3
OUTPUT Board[r, c]
NEXT c
NEXT r
Interactive Exam Practice
Scenario: Declare an empty 1D array capable of holding 5 STRING values. Write an algorithm that uses a loop to ask the user to input 5 names, and saves each name sequentially into the array.
Hover or tap the black box to reveal the examiner's solution. Click Run Code to test it instantly!
DECLARE ClassList : ARRAY[1:5] OF STRING DECLARE Index : INTEGER FOR Index ← 1 TO 5 OUTPUT "Enter a student name:" INPUT ClassList[Index] NEXT Index OUTPUT "Array completely populated!"