← IGCSE Computer Science Paper 2

Reading a value from a 2D array element

Gives the value stored at that row and column of a 2D array. Use it in an expression or OUTPUT, e.g. OUTPUT NoughtsAndCrosses[2,3] shows the value at row 2, column 3.

Understanding Reading a value from a 2D array element in IGCSE Computer Science Paper 2

What it does: Each Name[row, column] gives a value in the expression, so the two stored values can be compared with an operator such as >. The first index picks the row (the student) and the second picks the column (the subject), so this displays the Maths mark of the third student. Score ← Marks[3,1] copies the value from the array into Score. Putting the array element on the left would write into the array instead of reading from it. A 2D array needs two indexes, a row and a column, every time you read an element. A single index is not enough.

Common mistakes: Array indexes use square brackets, not round ones. It should be OUTPUT Board[2,3]. The row comes first and the column second. Row 3, column 2 is Marks[3,2], not Marks[2,3].

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 469–478) and word search (Modules 459–478).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which statement displays the value at row 2, column 3 of NoughtsAndCrosses?
OUTPUT NoughtsAndCrosses[2,3]OUTPUT NoughtsAndCrosses[3,2]
Matches
OUTPUT NoughtsAndCrosses[2][3]
↓
Separate brackets are used for the indexes. In Cambridge pseudocode both indexes go in one pair of square brackets, separated by a comma: NoughtsAndCrosses[2,3].
Applying
Meanings
Term
Name[row, column]
Meaning
Gives the value stored at that row and column of a 2D array. Use it in an expression or OUTPUT, e.g. OUTPUT NoughtsAndCrosses[2,3] shows the value at row 2, column 3.
Practice
OUTPUT NoughtsAndCrosses[2,3]
Testing
Gaps
NoughtsAndCrosses[2,3]
Check Answer
Spots
2Board[1,1] ← "O"
3OUTPUT Board(2,3)

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Camel' badge — Endurance Champion, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which statement displays the value at row 2, column 3 of NoughtsAndCrosses?
A. OUTPUT NoughtsAndCrosses[2,3] ✓
B. OUTPUT NoughtsAndCrosses[3,2]
The row number comes first and the column number second, so [2,3] is row 2, column 3. [3,2] would read row 3, column 2.
2. What does Marks[1,2] give you in an expression?
A. The value at row 1, column 2 ✓
B. The value at column 1, row 2
In Name[row, column] the first index is always the row and the second is always the column.
3. Which line reads an element of a 2D array into a variable?
A. Marks[3,1] ← Score
B. Score ← Marks[3,1] ✓
Score ← Marks[3,1] copies the value from the array into Score. Putting the array element on the left would write into the array instead of reading from it.
4. Which IF statement correctly compares two elements of a 2D array?
A. IF Marks[1] > Marks[2] THEN
B. IF Marks[1,2] > Marks[2,2] THEN ✓
A 2D array needs two indexes, a row and a column, every time you read an element. A single index is not enough.
5. Marks[2,1] holds 65 and Marks[2,2] holds 70. What does OUTPUT Marks[2,2] show?
A. 70 ✓
B. 65
Marks[2,2] is row 2, column 2, which holds 70. Marks[2,1] is the one that holds 65.

Match the Pairs

OUTPUT NoughtsAndCrosses[2,3] → Displays the value stored at row 2, column 3 of the NoughtsAndCrosses array
Winner ← Marks[4,2] → Copies the value at row 4, column 2 of Marks into the variable Winner
Compare two elements of a 2D array in an IF statement → IF Marks[1,2] > Marks[3,2] THEN
Read a value from a table of marks: row 3 is the third student, column 1 is Maths → OUTPUT Marks[3,1]
OUTPUT NoughtsAndCrosses[2][3] → Separate brackets are used for the indexes. In Cambridge pseudocode both indexes go in one pair of square brackets, separated by a comma: NoughtsAndCrosses[2,3].
OUTPUT NoughtsAndCrosses[3,2] → The row and column are swapped. To show row 2, column 3 the indexes must be written in the order [2,3], row first and then column.

Key Term

Name[row, column]
Gives the value stored at that row and column of a 2D array. Use it in an expression or OUTPUT, e.g. OUTPUT NoughtsAndCrosses[2,3] shows the value at row 2, column 3.

Fill in the Blanks

1. OUTPUT NoughtsAndCrosses[2,3]
Hint: Type the keyword that displays a value on the screen.
2. // Copy row 3, column 2 into Score Score ← Marks[3,2]
Hint: Type the column index that the comment asks for.
3. IF Marks[1,2] > Marks[2,2] THEN OUTPUT Marks[1,2] ENDIF
Hint: Type the comparison operator that checks whether the first element is greater than the second.
4. Top ← Marks[2,3] OUTPUT Top
Hint: Type the variable that holds the copied element so its value is displayed.
5. // Show the mark in row 3, column 1 OUTPUT Marks[3,1]
Hint: Type the row index that the comment describes.

Spot the Error

Question 1
A Board[2,3] ← "X"
B Board[1,1] ← "O"
C OUTPUT Board(2,3)
Line C — Array indexes use square brackets, not round ones. It should be OUTPUT Board[2,3].
Question 2
A // Show row 3, column 2
B OUTPUT Marks[2,3]
C OUTPUT Marks[1,1]
Line B — The row comes first and the column second. Row 3, column 2 is Marks[3,2], not Marks[2,3].
Question 3
A // Copy Marks[2,2] into Score
B Score ← 0
C Marks[2,2] ← Score
Line C — To copy an element into a variable, the variable goes on the left of the arrow: Score ← Marks[2,2]. The broken line overwrites the array element instead.
Question 4
A Marks[1,1] ← 60
B Marks[1,2] ← 72
C IF Marks[1,1] < Marks[1,2]
D THEN OUTPUT Marks[1]
E ENDIF
Line D — A 2D array element needs both a row and a column. It should be OUTPUT Marks[1,2].
Question 5
A Board[1,1] ← "X"
B Board[2,2] ← "X"
C IF Board[1,1] ← Board[2,2]
D THEN OUTPUT "Win"
E ENDIF
Line C — An IF compares values with =, not the assignment arrow. It should be IF Board[1,1] = Board[2,2].

Student with a class code? Join your class →