← IGCSE Computer Science Paper 2

Declaring a 2D array: ARRAY[l1:u1, l2:u2]

Declares a 2D array called Grid. The first range is the rows, the second is the columns, split by a comma. All elements share one data type, here CHAR.

Understanding Declaring a 2D array: ARRAY[l1:u1, l2:u2] in IGCSE Computer Science Paper 2

What it does: The comma between 1:5 and 1:8 splits the first dimension range from the second dimension range. OF CHAR sets one data type for all nine elements, so none of them can hold a different type. A 2D declaration puts both ranges inside ONE pair of square brackets, split by a comma. Each dimension has its own range. The rows can start at 0 while the columns start at 1. Both ranges here cover 3 values. The declaration needs OF between the ranges and the data type, otherwise it is not valid pseudocode.

Common mistakes: A declaration needs a colon between the identifier and ARRAY. It should be DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR, so the first line should be DECLARE Grid :. The first range is 1:3, so the row index can only be 1, 2 or 3. Row 4 is out of range. It should be Board[3, 3] ← 'O'.

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 correctly declares a 2D array for a 3 by 3 noughts and crosses board?
DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHARDECLARE NoughtsAndCrosses : ARRAY[1:3][1:3] OF CHAR
Matches
DECLARE Grid : ARRAY[1:3][1:3] OF CHAR
↓
The two ranges are written in separate square brackets. They must be in one pair of brackets separated by a comma: ARRAY[1:3, 1:3].
Applying
Meanings
Term
DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR
Meaning
Declares a 2D array called Grid. The first range is the rows, the second is the columns, split by a comma. All elements share one data type, here CHAR.
Practice
DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHAR
Testing
Gaps
Board : ARRAY[1:3, 1:3] OF CHAR
Check Answer
Spots
1DECLARE Grid =
2 ARRAY[1:3, 1:3] OF CHAR

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

The 'Arctic Fox' badge — Tundra Tracker, 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 correctly declares a 2D array for a 3 by 3 noughts and crosses board?
A. DECLARE NoughtsAndCrosses : ARRAY[1:3][1:3] OF CHAR
B. DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHAR ✓
A 2D declaration puts both ranges inside ONE pair of square brackets, split by a comma.
2. In ARRAY[1:4, 1:6] OF INTEGER, what separates the range for the rows from the range for the columns?
A. A comma ✓
B. A semicolon
A comma separates the two ranges. The colon is only used inside each range, between the lower and upper bound.
3. Which declaration gives an array with 5 rows and 2 columns?
A. DECLARE Scores : ARRAY[1:2, 1:5] OF INTEGER
B. DECLARE Scores : ARRAY[1:5, 1:2] OF INTEGER ✓
The first range is the rows and the second is the columns, so 5 rows and 2 columns is [1:5, 1:2].
4. True or false: ARRAY[0:2, 1:3] is a valid pair of ranges, because each dimension can have its own lower bound.
A. True ✓
B. False
Each dimension has its own range. The rows can start at 0 while the columns start at 1. Both ranges here cover 3 values.
5. Which declaration is wrong because the array is meant to hold CHAR values in some elements and INTEGER values in others?
A. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR and INTEGER ✓
B. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
All elements of an array share one data type, so you write just one type after OF. You cannot mix two.

Match the Pairs

DECLARE NoughtsAndCrosses : ARRAY[1:3, 1:3] OF CHAR → Declares a 2D array with 3 rows and 3 columns, where every element stores one CHAR
DECLARE Marks : ARRAY[0:4, 0:2] OF INTEGER → Declares a 2D array with indexes 0 to 4 in the first dimension and 0 to 2 in the second, storing INTEGER values
The two ranges for the two dimensions are separated by a comma inside the square brackets → DECLARE Seats : ARRAY[1:5, 1:8] OF BOOLEAN
Every element in a 2D array shares one data type, written after OF → DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
DECLARE Grid : ARRAY[1:3][1:3] OF CHAR → The two ranges are written in separate square brackets. They must be in one pair of brackets separated by a comma: ARRAY[1:3, 1:3].
DECLARE Scores : ARRAY[1:4, 1:3] CHAR → The keyword OF is missing before the data type. It should be ARRAY[1:4, 1:3] OF CHAR.

Key Term

DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR
Declares a 2D array called Grid. The first range is the rows, the second is the columns, split by a comma. All elements share one data type, here CHAR.

Fill in the Blanks

1. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
Hint: Type the keyword that starts every array declaration.
2. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
Hint: Type the upper bound of the column range for a noughts and crosses board with three columns.
3. DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR
Hint: Type the keyword that links the two ranges to the data type.
4. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
Hint: Type the data type for a board where each square holds a single X or O.
5. DECLARE Table : ARRAY[0:2, 0:3] OF INTEGER
Hint: Type the lower bound of the second range so the columns are numbered from the start of a zero-based count.

Spot the Error

Question 1
A DECLARE Grid =
B ARRAY[1:3, 1:3] OF CHAR
C Grid[1, 1] ← 'X'
D OUTPUT Grid[1, 1]
Line A — A declaration needs a colon between the identifier and ARRAY. It should be DECLARE Grid : ARRAY[1:3, 1:3] OF CHAR, so the first line should be DECLARE Grid :
Question 2
A DECLARE Board :
B ARRAY[1:3, 1:3] OF CHAR
C Board[4, 3] ← 'O'
D OUTPUT Board[3, 3]
Line C — The first range is 1:3, so the row index can only be 1, 2 or 3. Row 4 is out of range. It should be Board[3, 3] ← 'O'.
Question 3
A DECLARE Seats :
B ARRAY[0:2; 0:4] OF BOOLEAN
C Seats[0, 0] ← TRUE
Line B — The two ranges must be separated by a comma, not a semicolon. It should be ARRAY[0:2, 0:4] OF BOOLEAN.
Question 4
A DECLARE Marks :
B ARRAY[1:2, 1:3] OF INTEGER
C Marks[1, 1] ← 70
D Marks[2, 3] ← "pass"
Line D — All elements share one data type. The array is declared OF INTEGER, so a string cannot be stored in it. It should be Marks[2, 3] ← 85.
Question 5
A DECLARE Grid :
B ARRAY[1:3, 1:3] OF CHAR
C Grid[1, 2] ← 'X'
D OUTPUT Grid[2]
Line D — A 2D array needs two indexes, one for the row and one for the column. It should be OUTPUT Grid[1, 2].

Student with a class code? Join your class →