📘 Paper 2 · Topic 8: Programming
8.2 Arrays
Cambridge IGCSE Computer Science 0478 · ~15 min read · ⭐ Pro

What is an Array?

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.

1D Array visualised (scores[1:5])

72
[1]
85
[2]
91
[3]
60
[4]
78
[5]

Declaring Arrays in Cambridge Pseudocode

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.

Accessing and Assigning Array Elements

scores[1] ← 72
scores[2] ← 85
OUTPUT scores[3]   // outputs the value at index 3

Using Loops with Arrays

Input 5 values into an array

DECLARE scores : ARRAY[1:5] OF INTEGER
FOR i ← 1 TO 5
    INPUT scores[i]
NEXT i

Output all values

FOR i ← 1 TO 5
    OUTPUT scores[i]
NEXT i

Find the total and average

total ← 0
FOR i ← 1 TO 5
    total ← total + scores[i]
NEXT i
average ← total / 5
OUTPUT average

Find the maximum value

maximum ← scores[1]
FOR i ← 2 TO 5
    IF scores[i] > maximum THEN
        maximum ← scores[i]
    ENDIF
NEXT i
OUTPUT maximum

2D Arrays

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

Accessing 2D array elements

grid[2, 3] ← 15   // row 2, column 3
OUTPUT grid[1, 1]

Nested loop to fill a 2D array

FOR row ← 1 TO 3
    FOR col ← 1 TO 3
        INPUT grid[row, col]
    NEXT col
NEXT row
Exam tip: When writing array pseudocode for an exam, always DECLARE the array first. Use FOR loops to process arrays. If asked to "search" an array, show a loop checking each element. Cambridge index notation is square brackets: scores[i]
⚠️ Common Mistakes
  • Forgetting to DECLARE the array before using it
  • Using wrong index — if ARRAY[1:5], valid indices are 1,2,3,4,5 only
  • Mixing up the row and column in 2D arrays: grid[row, col] not grid[col, row]
  • Using a variable that doesn't match the loop counter to access the array
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — Arrays

4 questions · 11 marks

Q1Write the pseudocode declaration for an array called temperatures that stores 7 REAL values. [2]
✅ Mark scheme
DECLARE temperatures : ARRAY[1:7] OF REAL [2] (1 mark for ARRAY keyword and bounds, 1 mark for correct data type REAL)
Q2Write pseudocode to input 10 integers into an array called data, then output their total. [4]
✅ Mark scheme
DECLARE data : ARRAY[1:10] OF INTEGER [1]; total ← 0 [1]; FOR i ← 1 TO 10; INPUT data[i] [1]; total ← total + data[i]; NEXT i; OUTPUT total [1]
Q3An array marks[1:5] contains [60, 75, 45, 90, 55]. Write pseudocode to find and output the minimum value. [3]
✅ Mark scheme
minimum ← marks[1] [1]; FOR i ← 2 TO 5; IF marks[i] < minimum THEN minimum ← marks[i] ENDIF [1]; NEXT i; OUTPUT minimum [1]
Q4State TWO advantages of using an array instead of separate variables to store 100 exam scores. [2]
✅ Mark scheme
Any two: (1) Only one identifier needed instead of 100 separate variables [1]; (2) Can use a loop to process all elements instead of writing repetitive code [1]; (3) Easier to maintain — changing array size only requires updating one declaration [1]
Quiz — Arrays
Q 1 of 7
Score
/ 7
Click to reveal
TermDefinition
🎯

Mini Test — Arrays

10 minutes · mixed marks

← 8.1c Iteration Topic 8: Programming Next: 8.3 Procedures & Functions →
🔒
Pro Content
Upgrade to access all lessons.
£7.99/month
or £59/year
Subscribe now →