← IGCSE Computer Science Paper 2

Two-dimensional array: rows and columns

A table of rows and columns held in one variable. Each element needs two indexes: the first is the row (across), the second is the column (down), e.g. Marks[2, 3].

Understanding Two-dimensional array: rows and columns in IGCSE Computer Science Paper 2

What it does: Grid[1, 3] means row 1 (the top row, across) and column 3 (the third column, down). The X is stored in that one square. Each student is a row (1:4) and each test is a column (1:3). The array holds whole-number marks, so the type is INTEGER. A grid needs two sets of bounds, one for the rows and one for the columns. ARRAY[1:3] is a 1D array and only has 3 elements. The first index is always the row and the second is always the column. So Marks[2, 3] is row 2, column 3. A row on its own only picks out a whole line of the table. You need the row and the column to find one single element.

Common mistakes: A 2D array element needs two indexes: the row and then the column. Board[3] gives only one. It should be Board[3, 1] ← "X". Array indexes go inside square brackets, not round brackets. The line should be Marks[2, 2] ← 91.

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 459–468) 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
A noughts and crosses board has 3 rows and 3 columns. Which declaration suits it?
DECLARE Board : ARRAY[1:3] OF CHARDECLARE Board : ARRAY[1:3, 1:3] OF CHAR
Matches
Grid[2] ← 'O'
↓
Only one index is given. An element of a 2D array needs two indexes, a row and a column, such as Grid[2, 1].
Applying
Meanings
Term
2D array
Meaning
A table of rows and columns held in one variable. Each element needs two indexes: the first is the row (across), the second is the column (down), e.g. Marks[2, 3].
Practice
DECLARE Marks : ARRAY[1:3, 1:4] OF INTEGER
Testing
Gaps
DECLARE Board : [1:3, 1:3] OF CHAR
Check Answer
Spots
2Board[2, 2] ← "O"
3Board[3] ← "X"

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

The 'Flamingo' badge — Balanced Coder, 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. A noughts and crosses board has 3 rows and 3 columns. Which declaration suits it?
A. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR ✓
B. DECLARE Board : ARRAY[1:3] OF CHAR
A grid needs two sets of bounds, one for the rows and one for the columns. ARRAY[1:3] is a 1D array and only has 3 elements.
2. In Marks[2, 3], what does the first index (2) tell you?
A. The column number
B. The row number ✓
The first index is always the row and the second is always the column. So Marks[2, 3] is row 2, column 3.
3. Which statement about a 2D array is true?
A. Rows run across and columns run down ✓
B. Rows run down and columns run across
Think of a table. Each row is a horizontal line going across, and each column is a vertical line going down.
4. Which element is in row 1, column 3 of the Board array?
A. Board[3, 1]
B. Board[1, 3] ✓
Row comes first and column second. Board[3, 1] would be row 3, column 1, which is a different square.
5. How many index numbers do you need to identify ONE element in a 2D array?
A. Two: a row and a column ✓
B. One: just the row
A row on its own only picks out a whole line of the table. You need the row and the column to find one single element.

Match the Pairs

DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR → A 2D array with 3 rows and 3 columns that holds characters, such as a noughts and crosses board
Marks[2, 3] → The element in row 2 and column 3 of the Marks table
The first index is the row and the second is the column, so this puts an X in the top row, third column of a noughts and crosses grid → Grid[1, 3] ← 'X'
A table of marks for 4 students and 3 tests needs rows and columns, so the array has two ranges → DECLARE Marks : ARRAY[1:4, 1:3] OF INTEGER
Grid[2] ← 'O' → Only one index is given. An element of a 2D array needs two indexes, a row and a column, such as Grid[2, 1].
DECLARE Marks : ARRAY[1:4] OF INTEGER → Only one range is given, so this is a 1D list, not a table. A 2D array needs two ranges, such as ARRAY[1:4, 1:3].

Key Term

2D array
A table of rows and columns held in one variable. Each element needs two indexes: the first is the row (across), the second is the column (down), e.g. Marks[2, 3].

Fill in the Blanks

1. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
Hint: Type the keyword that declares a table with rows and columns.
2. // Put X in row 2, column 3 Board[2, 3] ← 'X'
Hint: Type the second index, which is the column number.
3. // Student 4 scored 75 in test 2 Marks[4, 2] ← 75
Hint: Type the first index, which is the row for that student.
4. // Show the mark in row 2, column 3 OUTPUT Marks[2, 3]
Hint: Type the keyword that displays a value on the screen.
5. FOR Row ← 1 TO 5 OUTPUT Marks[Row, 1] NEXT Row
Hint: Type the loop variable that selects each row in the first index.

Spot the Error

Question 1
A Board[1, 1] ← "X"
B Board[2, 2] ← "O"
C Board[3] ← "X"
D OUTPUT Board[2, 2]
Line C — A 2D array element needs two indexes: the row and then the column. Board[3] gives only one. It should be Board[3, 1] ← "X".
Question 2
A Marks[1, 1] ← 72
B Marks[1, 2] ← 65
C Marks[2, 1] ← 80
D Marks(2, 2) ← 91
Line D — Array indexes go inside square brackets, not round brackets. The line should be Marks[2, 2] ← 91.
Question 3
A // Marks[student, test]
B Marks[3, 2] ← 58
C Total ← Marks[3, 1]
D Total ← Total + Marks[2, 3]
Line D — The first index is the row (the student) and the second is the column (the test). Student 3's second test is Marks[3, 2], not Marks[2, 3].
Question 4
A Row ← 2
B Col ← 3
C Grid[Row, Col, 1] ← "X"
D OUTPUT Grid[Row, Col]
Line C — A 2D array needs exactly two indexes, one for the row and one for the column. A third index is wrong. It should be Grid[Row, Col] ← "X".
Question 5
A Board[3, 1] ← "O"
B OUTPUT "Top right square:"
C OUTPUT Board[1, 3]
Line A — The top right square is in row 1 (the first index) and column 3 (the second index). Board[3, 1] is the bottom left square. It should be Board[1, 3] ← "O".

Student with a class code? Join your class →