← IGCSE Computer Science Paper 2

Writing a value into a 2D array element

Stores a value in one element of a 2D array. Give the row index first, then the column index, e.g. NoughtsAndCrosses[2,3] ← 'X' puts a CHAR in row 2, column 3.

Understanding Writing a value into a 2D array element in IGCSE Computer Science Paper 2

What it does: The row index 1 comes first, the column index 1 comes second, and the CHAR 'O' is in single quotes. Swapping the indexes reaches a different element. [1,3] is row 1, column 3 and [3,1] is row 3, column 1, so these are two separate elements. The centre of a 3 x 3 grid is row 2, column 2. Grid[3,3] is the bottom right corner. In IGCSE pseudocode, both indexes go inside one pair of brackets, separated by a comma: Board[2,3]. Each dimension needs its own index, so the fix is NoughtsAndCrosses[2,3] ← 'X'.

Common mistakes: A CHAR value must be written in single quotes. Double quotes make it a STRING. Line 1 should be Board[1,1] ← 'X'. The row index comes first and the column index second. Row 2, column 3 is [2,3], not [3,2], which is a different element.

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 line stores 'X' in row 2, column 3 of NoughtsAndCrosses?
NoughtsAndCrosses[3,2] ← 'X'NoughtsAndCrosses[2,3] ← 'X'
Matches
NoughtsAndCrosses[2] ← 'X'
↓
A 2D array needs two index values, a row and a column. Only one index is given, so no single element is identified.
Applying
Meanings
Term
Name[row, column] ← value
Meaning
Stores a value in one element of a 2D array. Give the row index first, then the column index, e.g. NoughtsAndCrosses[2,3] ← 'X' puts a CHAR in row 2, column 3.
Practice
DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHAR
Testing
Gaps
NoughtsAndCrosses[,3] ← 'X'
Check Answer
Spots
1Board[1,1] ← "X"
2Board[2,2] ← 'O'

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

The 'Lion' badge — Inheritance King, 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 line stores 'X' in row 2, column 3 of NoughtsAndCrosses?
A. NoughtsAndCrosses[2,3] ← 'X' ✓
B. NoughtsAndCrosses[3,2] ← 'X'
The row index comes first and the column index second, so row 2, column 3 is written [2,3].
2. Which statement stores a value in a 2D array element correctly?
A. Board[1] ← 'O'
B. Board[1,1] ← 'O' ✓
A 2D array needs two index values, one for the row and one for the column. A single index is not enough.
3. Which line correctly stores a CHAR value in a 2D array?
A. Grid[1,2] ← "X"
B. Grid[1,2] ← 'X' ✓
CHAR values are written in single quotes. Double quotes are used for STRING values.
4. In Board[3,1] ← 'O', which element receives the value?
A. Row 3, column 1 ✓
B. Row 1, column 3
The first index is the row and the second is the column, so Board[3,1] is row 3, column 1.
5. After Grid[1,3] ← 'X' and Grid[3,1] ← 'X', how many different elements have been changed?
A. Two ✓
B. One
Swapping the indexes reaches a different element. [1,3] is row 1, column 3 and [3,1] is row 3, column 1, so these are two separate elements.

Match the Pairs

NoughtsAndCrosses[2,3] ← 'X' → Stores the CHAR 'X' in the element in row 2, column 3 of the 2D array
NoughtsAndCrosses[3,2] ← 'O' → Stores the CHAR 'O' in row 3, column 2, a different element from row 2, column 3
Write a CHAR value into the element in row 1, column 1 of a 2D array (the CHAR goes in single quotes) → NoughtsAndCrosses[1,1] ← 'O'
Write a value into one element, giving the row index first and then the column index → Grid[3,1] ← 'X'
NoughtsAndCrosses[2] ← 'X' → A 2D array needs two index values, a row and a column. Only one index is given, so no single element is identified.
NoughtsAndCrosses[1,2] ← "X" → The CHAR value is in double quotes. A CHAR must be written in single quotes, and double quotes are for STRING values.

Key Term

Name[row, column] ← value
Stores a value in one element of a 2D array. Give the row index first, then the column index, e.g. NoughtsAndCrosses[2,3] ← 'X' puts a CHAR in row 2, column 3.

Fill in the Blanks

1. NoughtsAndCrosses[2,3] ← 'X'
Hint: Type the row index. The row always comes first inside the square brackets.
2. NoughtsAndCrosses[2,3] ← 'X'
Hint: Type the column index. The column always comes second inside the square brackets.
3. NoughtsAndCrosses[1,1] ← 'O'
Hint: Type the name of the 2D array being written to.
4. NoughtsAndCrosses[2,3] ← 'X' // Put an O in row 3, column 2 NoughtsAndCrosses[3,2] ← 'O'
Hint: Type the row index for the O, using the comment. Row comes first, so do not swap it with the column.
5. NoughtsAndCrosses[1,1] ← 'O'
Hint: Type the pseudocode assignment symbol that stores the value in the element.

Spot the Error

Question 1
A Board[1,1] ← "X"
B Board[2,2] ← 'O'
C Board[3,3] ← 'X'
Line A — A CHAR value must be written in single quotes. Double quotes make it a STRING. Line 1 should be Board[1,1] ← 'X'.
Question 2
A // X goes in row 2, column 3
B NoughtsAndCrosses[3,2] ← 'X'
C OUTPUT NoughtsAndCrosses[2,3]
Line B — The row index comes first and the column index second. Row 2, column 3 is [2,3], not [3,2], which is a different element.
Question 3
A Score[1,1] ← 12
B Score[1,2] ← 15
C Score[2,1] ← 9
D Score[2,2] = 14
Line D — A value is stored in an array element with the assignment arrow ←. A single = is a comparison in pseudocode. It should be Score[2,2] ← 14.
Question 4
A Board[1][2] ← 'O'
B Board[2,2] ← 'X'
C OUTPUT Board[1,2]
Line A — A 2D array element uses one pair of brackets with both indexes separated by a comma. It should be Board[1,2] ← 'O'.
Question 5
A Board[1,1] ← 'X'
B Board[1,2] ← 'O'
C Board[1,3] ← 'X'
D Board[2,1] ← O
Line D — The CHAR value O has no quotes, so it looks like a variable name. A CHAR needs single quotes: Board[2,1] ← 'O'.

Student with a class code? Join your class →