Work with two-dimensional arrays
Use row and column indexes to represent a table, then process both dimensions with nested iteration.
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0984, 2026–2028 syllabus Version 4. It covers section 8.2 (Arrays) only. Pseudocode examples use the published Cambridge format; the separate 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers, a browser-based programming workspace and human subject-teacher review remain outstanding. Cambridge states that 0984 has the same 2026–2028 subject content as 0478, with 9–1 grading. In June and November, Cambridge lists 0984 in Administrative zone 3 and for centres in Oman and the UAE. Confirm availability for your centre and exam series with Cambridge International. The separately published 2029–2031 syllabus changes to Python 3 only and removes pseudocode; this 2026–2028 route does not cover those changes.
Before you begin
- Be comfortable following an ordered algorithm and tracing variable values. Each lesson introduces the Cambridge pseudocode form it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
What does Grid[2,3] identify?
What you will learn
- Declare and access a two-dimensional array
- Use two index values for one element
- Read or write every cell using nested loops
Two dimensions represent rows and columns
A two-dimensional array has an index for each dimension, such as DECLARE Grid : ARRAY[1:3, 1:4] OF INTEGER.
Grid[2,3] selects row 2, column 3. Each element has the declared data type, and both sets of bounds must be respected.
Nested loops visit every cell
Use an outer loop for rows and an inner loop for columns. The inner loop runs once for every row, so a 3 by 4 array contains 12 cells.
A variable can be used in each index. State the lower bounds because indexes may begin at 0 or 1.
Pause and explain
How many cells are in an array with 4 rows and 5 columns?
Worked example
How many elements are in Grid : ARRAY[1:3, 1:4] OF INTEGER, and which element is Grid[2,3]?
Show the worked solution
- There are 3 row indexes and 4 column indexes.
- Multiply 3 by 4 to get 12 elements.
- The two indexes select row 2, column 3.
Answer Grid contains 12 elements; Grid[2,3] is the value at row 2, column 3.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Declare a 2D array for a 3-by-3 game board of characters and assign X to row 2, column 1.
Give me a hint
Use two inclusive bounds and CHAR elements.
Compare my reasoning
- Declare both index ranges as 1:3.
- Choose CHAR because each cell holds one mark.
- Assign the value at [2,1].
DECLARE Board : ARRAY[1:3, 1:3] OF CHAR; Board[2,1] ← 'X'.
Look for these in your work
- Two dimensions
- CHAR type
- Correct indexes
A score table has 4 students and 3 tests. How many values are stored, and how many times does the inner loop run in total?
Give me a hint
The inner loop processes every test for each student.
Compare my reasoning
- There are 4 rows and 3 columns.
- There are 4 × 3 = 12 values.
- The inner loop runs 3 times on each of 4 rows, 12 total.
12 values; the inner body runs 12 times.
Look for these in your work
- Array size
- Nested iteration count
Nested loops output a table in which the row loop runs 2 times and the column loop runs 5 times. Describe the output order and total cells.
Give me a hint
The complete inner loop runs for each row.
Compare my reasoning
- For row 1, columns 1–5 are output.
- Then row 2's columns 1–5 are output.
- There are 2 × 5 = 10 cells.
The table is output row by row, five columns per row, for ten cells total.
Look for these in your work
- Order described
- Cell count
Common mistakes
- Supplying only one index for a 2D array
- Swapping the row and column indexes
- Using a loop bound that differs from the declaration
What can you explain now?
How many index values are needed to access one element in a 2D array?
Compare with the explanation
Two
One index selects each dimension, such as row and column.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
Why does a 2D array normally need nested loops to visit every element?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.