O Level · Computer Science 0478

Arrays

Revise Arrays for Computer Science 0478 (O Level) — revision notes and instant AI marking. Free to start.

📖 Revision notes · preview
  CIE IGCSE Computer Science

Arrays: The Complete Revision Guide

The big idea: An array is a single named box divided into fixed, ordered compartments that all hold the same type of thing — so instead of naming every value separately, you find any value by its position.

Summary — What This Chapter Covers

  • What an array actually is, and why it exists (fixed-size, single data type, ordered).
  • The index war: Python starts counting at 0, CIE pseudocode starts counting at 1.
  • How to declare, access, and modify elements in a 1D array — in both pseudocode and Python.
  • Using len() / a length variable to find how many elements are in an array.
  • Iterating through a 1D array with a FOR...NEXT loop.
  • 2D arrays — thinking of them as a grid with rows and columns, and how to navigate row-first, then column.
  • Declaring, accessing, and modifying elements in a 2D array — pseudocode uses [row, col], Python uses [row][col].
  • Nested FOR...NEXT loops to iterate through every cell of a 2D array.

1. What Is an Array?

Imagine you need to store the test scores of 5 students. You create five separate variables — score1, score2, score3, score4, score5 — but that's clunky, and it falls apart completely if you have 500 students instead of 5. You'd need 500 variable names, and looping through them would be impossible because you can't easily say "give me variable number 347" in a loop.

An array solves this. Think of it like a strip of numbered pigeonholes bolted to a wall. The whole strip has one name (say, scores), and each pigeonhole has a position number. To get a value out, you don't need a new variable name — you just say "give me the value in pigeonhole 3."

Formally, an array is defined by three properties, and all three matter for exam answers:

Definition to memorise word-for-word An array is an ordered, static (fixed-size) set of elements stored in a single, named block of memory, where every element must be the same data type.
  • Ordered — every element has a fixed position (an index), so the array always keeps the same sequence unless you explicitly change it.
  • Static / fixed-size — once you declare an array to hold, say, 5 elements, it always has exactly 5 slots. You can't stretch it to hold a 6th value without creating a new array. (This is different from a Python , which can grow — but for IGCSE purposes, arrays are treated as fixed-size.)
  • Single data type — an array of integers can only hold integers. You can't mix a string into an array of numbers.

Visualising a 1D array

Here's the array ["B","E","A","D","S"] drawn out — notice this uses zero-indexing (the Python/most-languages convention):

0
B
1
E
2
A
3
D
4
S

Array length is 5 · First element is at index 0 · The 4th element ("D") sits at index 3

The single most important rule in this whole chapter

In CIE pseudocode, indexes start at 1. In Python, indexes start at 0. This is the #1 thing that trips students up in exams — because you'll be shown pseudocode and Python for the exact same array, and the same real-world position (e.g. "the 4th element") will be written as [4] in pseudocode but [3] in Python.

Practice Question 1

An array called fruits stores 6 values. In CIE pseudocode, what index would you use to access the very last element? What about in Python?

Practice Question 2

Explain why you could not use an array to store a mixed list containing a student's name (a string) and their age (an integer) in the same array.

2. Creating, Accessing & Modifying a 1D Array

There are three things you'll always be asked to do with an array: create it, read (access) a value from it, and write (modify) a value in it. Let's go through the exact syntax for each, side by side in both languages.

Creating an array

PseudocodePython
PseudocodePython
DECLARE MyArray : ARRAY[1:5] OF INTEGERarray = [1, 2, 3, 4, 5]
Reading the pseudocode declaration DECLARE MyArray : ARRAY[1:5] OF INTEGER means: "Create an array called MyArray, with indexes running from 1 to 5 (so 5 slots total), and every value stored must be an INTEGER."

You can also declare a blank array and fill it slot by slot with assignment statements — this is exactly what happens in the worked example below.

Accessing a single element

PseudocodePython
MyArray[1] ← gets 1st elementarray[0] ← gets 1st element

Modifying a single element

PseudocodePython
MyArray[index] ← newValuearray[index] = newValue

Notice pseudocode uses a left-pointing arrow for assignment, while Python uses a single equals sign =. This is consistent across all of CIE pseudocode, not just arrays — always keep it straight in your head.

Finding the length

Python has a handy built-in function, len(array), that instantly tells you how many elements are in an array. CIE pseudocode has no built-in length function — you either already know the size from the DECLARE statement, or you store it yourself in a variable.

Full worked example — building and using MyArray

Pseudocode
// Creating a one-dimensional array
DECLARE MyArray : ARRAY[1:5] OF INTEGER
MyArray[1] ← 1
MyArray[2] ← 2
MyArray[3] ← 3
MyArray[4] ← 4
MyArray[5] ← 5

// Accessing elements
OUTPUT MyArray[1]      // Output: 1
OUTPUT MyArray[3]      // Output: 3

// Modifying an element
MyArray[2] ← 10
// MyArray is now: [1, 10, 3, 4, 5]

// Iterating over the array
DECLARE Index : INTEGER
FOR Index ← 1 TO 5
  OUTPUT MyArray[Index]
NEXT Index
// Output: 1, 10, 3, 4, 5

// Length of the array
DECLARE Length : INTEGER
Length ← 5
OUTPUT Length          // Output: 5
Python
# Creating a one-dimensional array
array = [1, 2, 3, 4, 5]

# Accessing elements
print(array[0])   # Output: 1
print(array[2])   # Output: 3

# Modifying an element
array[1] = 10
print(array)  # [1, 10, 3, 4, 5]

# Iterating over the array
for element in array:
    print(element)
# Output: 1, 10, 3, 4, 5


# Length of the array
length = len(array)
print(length)   # Output: 5
Spot the pattern

In the pseudocode above, MyArray[1] and MyArray[3] print 1 and 3 — the value happens to equal the index because we filled the array in order. But look at the Python version: array[0] and array[2] print exactly the values, 1 and 3. That's because index 0 in Python and index 1 in pseudocode both point at the — they're just counted differently. Always translate by position ("the 3rd element"), not by the raw number.

Practice Question 3

Given the pseudocode array declared as DECLARE Colours : ARRAY[1:4] OF STRING with values ["Red","Green","Blue","Yellow"] assigned in order, write the line of pseudocode that changes "Blue" to "Purple".

3. 2-Dimensional Arrays

A 1D array is a single strip of pigeonholes. A 2D array is what you get when you stack several of those strips on top of each other — now you have rows columns, exactly like a spreadsheet or a table.

The most natural way to think about a 2D array is as a grid: the row index tells you which strip (which row) to look in, and the column index tells you which pigeonhole along that strip to open.

Navigation rule to memorise When navigating a 2D array, you always go down the rows first, then across the columns. The convention in this chapter is [row, column] in pseudocode and [row][column] in Python — but always check the example given in the exam question, because occasionally a question will define it as [column, row] instead!

Visualising a 2D array

Here's a 3×5 grid of letters spelling a hidden word, read row by row:

01234
0BEADS
1SEVEN
2WHITE

The left index picks the row. The right index picks the column. So position [1,2] (row 1, column 2) gives you the letter V.

Declaring a 2D array

Example: 3 people, each with a name and a number DECLARE NamesAndNumbers : ARRAY[1:3, 1:2] OF STRING

1:3 = 3 rows (one row per person)  ·  1:2 = 2 columns (one for name, one for number)  ·  OF STRING = both names and phone numbers are stored as strings, because arrays must hold a single data type — so even a phone number gets stored as text.

Worked example — building the "players" 2D array

Four players, each with a name and a score, stored as a 4-row, 2-column array:

Pseudocode
// 4 rows, 2 columns (name and score)
DECLARE players : ARRAY[1:4, 1:2] OF STRING

// Assign values to each player
players[1,1] ← "Alice"
players[1,2] ← "25"
players[2,1] ← "Bob"
players[2,2] ← "30"
players[3,1] ← "Charlie"
players[3,2] ← "22"
players[4,1] ← "Daisy"
players[4,2] ← "28"
Python
# Each player: [name, score]
players = [
    ["Alice", 25],
    ["Bob", 30],
    ["Charlie", 22],
    ["Daisy", 28]
]

Notice Python is happy to mix a string and an integer inside ["Alice", 25] because that's just a small nested inside a bigger list — Python lists are more flexible than the strict "array" definition CIE pseudocode uses. But in strict pseudocode terms, everything has to be declared as one type (STRING here), which is why the score is stored as the text "25" rather than the number 25.

Modifying an element in a 2D array

TaskPseudocodePython
Change "Charlie" to "Holly"players[3,1] ← "Holly"players[2][0] = "Holly"

Charlie is the 3rd person, so pseudocode row index is 3 (1-indexed); Python's row index is 2 (0-indexed). The name is the 1st item in each row, so pseudocode column is 1; Python column is 0.

Quick self-check

Can you see why players[3,1] and players[2][0] are the exact same box in memory? Row: 3rd person either way. Column: 1st value (the name) either way. Only the counting system changes — the real-world position doesn't.

Full worked example — a 3×3 numeric grid

Pseudocode
DECLARE Array2D : ARRAY[1:3, 1:3] OF INTEGER
Array2D[1,1] ← 1
Array2D[1,2] ← 2
Array2D[1,3] ← 3
Array2D[2,1] ← 4
Array2D[2,2] ← 5
Array2D[2,3] ← 6
Array2D[3,1] ← 7
Array2D[3,2] ← 8
Array2D[3,3] ← 9

// Accessing elements
OUTPUT Array2D[1,1]   // Output: 1
OUTPUT Array2D[2,3]   // Output: 6
Python
array_2d = [[1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]]

# Accessing elements
print(array_2d[0][0])  # Output: 1
print(array_2d[1][2])  # Output: 6
Practice Question 4

Using the Array2D grid above, what pseudocode statement would you write to output the value 8, and what is its Python equivalent?

4. Iterating Through a 2D Array

To visit every single element of a 2D array, one loop isn't enough — you need a loop a loop, called a nested loop. Think of it like reading a book: the outer loop moves you down through the pages (rows), and for every page, the inner loop reads every word on that page (columns) before moving to the next page.

Pseudocode
DECLARE Row : INTEGER
DECLARE Col : INTEGER
FOR Row ← 1 TO 3
  FOR Col ← 1 TO 3
    OUTPUT Array2D[Row, Col]
  NEXT Col
NEXT Row
Python
for row in array_2d:
    for item in row:
        print(item, end=" ")
    print()  # newline after each row
How to read a nested loop The outer loop (Row) only advances to the next value the entire inner loop (Col) has finished running from start to end. So for a 3×3 grid: Row=1 runs Col 1,2,3 (3 outputs) → Row=2 runs Col 1,2,3 (3 more outputs) → Row=3 runs Col 1,2,3 (3 more outputs) = 9 outputs total, visiting every single cell exactly once.
Examiner tip (straight from the chapter)

In the exam, the question will always give you an example showing which order the array is being read from. Some questions use [row, column], others flip it to [column, row]. Always check the example given before answering — don't assume it's the same convention used here.

Worked example — the TV-watching table

A parent records minutes of TV watched by 4 children (Quinn, Lyla, Harry, Elias) across 5 days, stored in a 2D array called minsWatched using Python-style zero-indexing, rows = days, columns = children:

Quinn (0)Lyla (1)Harry (2)Elias (3)
Monday (0)34678978
Tuesday (1)56434556
Wednesday (2)122233445
Thursday (3)131092390
Friday (4)4710016723

Worked step-by-step: "Elias watched 78 minutes of TV on Monday" — how do we know?

  • Identify the row for Monday → Row 0
  • Identify the column for Elias → Column 3
  • Look up minsWatched[0][3] → value is 78
Practice Question 5

Using the table above, write a line of Python code to output the number of minutes Harry watched TV on Friday.

Practice Question 6

Using the table above, write a line of code (pseudocode Python) to output the number of minutes Quinn watched TV on Wednesday.


What to Memorise

Array An ordered, static set of elements in a fixed-size memory location, storing only ONE data type.
Index The position number used to locate an element. Pseudocode: starts at 1. Python: starts at 0.
1D array (linear array) A single row of elements, accessed with one index, e.g. array[3].
2D array A grid of elements (rows × columns), accessed with two indexes: [row, column] in pseudocode, [row][column] in Python.
DECLARE syntax (pseudocode) DECLARE name : ARRAY[lower:upper] OF type for 1D, add a second range for 2D.
Assignment arrow vs equals Pseudocode uses . Python uses =. Same meaning: store the right-hand value at the position on the left.
len() Python's built-in function to find array length. No equivalent exists in CIE pseudocode — you must know or store the size yourself.
FOR...NEXT loop Used to iterate through a 1D array. Nest two of them to iterate through every cell of a 2D array (row loop outside, column loop inside).

Concepts Checklist

Exam Tips

Mistake #1 — Mixing up index conventions

The single most common error: using 0-indexing in pseudocode, or 1-indexing in Python. If the question is written in pseudocode, count from 1. If it's written in Python, count from 0. Double-check which language the question is actually asking for before you write your index.

Mistake #2 — Confusing row and column order

Don't assume [row, column] is always correct — some exam questions define their 2D array as [column, row] instead. Always find the example given in the question (like "Elias watched 78 minutes on Monday, found at [0][3]") and work out the convention from that before answering later parts.

Mistake #3 — Forgetting arrays are fixed-size and single-type

If asked to explain something can't be stored in an array, or why an array is different from other structures, always mention BOTH properties: fixed size AND single data type. Markschemes usually award a point for each one separately.

Mistake #4 — Off-by-one errors in loops

When writing a FOR...NEXT loop to iterate a pseudocode array of size 5, the loop must run FOR Index ← 1 TO 5 — not 1 TO 4 (misses the last element) and not 0 TO 5 (goes out of bounds and reads an extra, non-existent element). In Python, range(len(array)) correctly gives you 0 to size-1.

What examiners actually look for
  • Correct index numbers matching the language used in the question (pseudocode vs Python).
  • Correct syntax — square brackets, comma for 2D pseudocode vs double brackets for 2D Python.
  • Using the exact variable/array name given in the question — not inventing your own.
  • For "write a line of code" questions worth 1 mark, a single correct statement is usually enough — don't overcomplicate with unnecessary loops.
  • For iteration questions, correctly nesting the loops (row loop OUTSIDE, column loop INSIDE) and correctly closing them (NEXT Col before NEXT Row).
🔓 Read the full Arrays note — free You're seeing the preview · free account, no card needed
Also in the full note
  • 2. Creating, Accessing & Modifying a 1D Array
What's inside
📖 Revision notes 🎯 Learn mode ✦ AI flashcards ✓ Instant AI marking 🧊 3D explorers 🧪 Experiments & simulations 📈 Progress tracking
📄 Practise Arrays with Computer Science 0478 past papers Every paper with its mark scheme — answer online, marked instantly. Open →

Read the full Arrays notes free

That's the preview — create a free account to read the rest, plus flashcards and practice questions with instant AI marking. No credit card.

Unlock the full notes free →

More Computer Science topics