← IGCSE Computer Science Paper 2

Working out how many elements a 2D array holds

The total number of elements in a 2D array. Each dimension holds upper - lower + 1 values, so ARRAY[1:3, 1:3] holds 3 * 3 = 9 and ARRAY[1:30, 1:4] holds 30 * 4 = 120.

Understanding Working out how many elements a 2D array holds in IGCSE Computer Science Paper 2

What it does: Multiplying the size of the two dimensions gives the total number of elements in the 2D array. Counting from the lower bound to the upper bound includes both ends, so you add 1 after subtracting. For 1:30 this is 30 - 1 + 1 = 30. Rows: 3 - 1 + 1 = 3. Columns: 3 - 1 + 1 = 3. Total = 3 * 3 = 9. 30 rows * 4 columns = 120. You multiply the dimensions, you do not add them. Upper - lower + 1 = 4 - 0 + 1 = 5. The 0 counts as an index.

Common mistakes: The number of elements is rows multiplied by columns, not added. It should be Total ← Rows * Cols, which gives 3 * 3 = 9. Each dimension holds upper - lower + 1 values. The +1 is missing, so Rows would be 29. It should be Rows ← 30 - 1 + 1, which gives 30.

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
How many elements does ARRAY[1:3, 1:3] hold?
69
Matches
ARRAY[1:3, 1:3] holds 3 + 3 = 6 elements
↓
The sizes of the dimensions were added instead of multiplied. It should be 3 * 3 = 9 elements.
Applying
Meanings
Term
rows * columns
Meaning
The total number of elements in a 2D array. Each dimension holds upper - lower + 1 values, so ARRAY[1:3, 1:3] holds 3 * 3 = 9 and ARRAY[1:30, 1:4] holds 30 * 4 = 120.
Practice
DECLARE Grid : ARRAY[1:3, 1:4] OF INTEGER
Testing
Gaps
total ← rows columns
Check Answer
Spots
3Cols ← 3
4Total ← Rows + Cols

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

The 'Octopus' badge — Multi-Tasker, 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. How many elements does ARRAY[1:3, 1:3] hold?
A. 9 ✓
B. 6
Rows: 3 - 1 + 1 = 3. Columns: 3 - 1 + 1 = 3. Total = 3 * 3 = 9.
2. How many elements does ARRAY[1:30, 1:4] hold?
A. 120 ✓
B. 34
30 rows * 4 columns = 120. You multiply the dimensions, you do not add them.
3. Which formula gives the total number of elements in a 2D array?
A. rows + columns
B. rows * columns ✓
Every row has a full set of columns, so the total is rows multiplied by columns.
4. How many values does one dimension of ARRAY[0:4, 1:3] have for its first index (0:4)?
A. 5 ✓
B. 4
Upper - lower + 1 = 4 - 0 + 1 = 5. The 0 counts as an index.
5. How many elements does ARRAY[0:4, 1:3] hold?
A. 12
B. 15 ✓
First dimension: 4 - 0 + 1 = 5. Second dimension: 3 - 1 + 1 = 3. Total = 5 * 3 = 15.

Match the Pairs

DECLARE Grid : ARRAY[1:3, 1:3] OF INTEGER → This 2D array has 3 rows and 3 columns, so it holds 3 * 3 = 9 elements
DECLARE Marks : ARRAY[1:30, 1:4] OF INTEGER → This 2D array has 30 rows and 4 columns, so it holds 30 * 4 = 120 elements
The total number of elements in a 2D array is the number of rows multiplied by the number of columns → Total ← Rows * Columns
The size of each dimension is the upper bound minus the lower bound plus one → Size ← Upper - Lower + 1
ARRAY[1:3, 1:3] holds 3 + 3 = 6 elements → The sizes of the dimensions were added instead of multiplied. It should be 3 * 3 = 9 elements.
ARRAY[1:30, 1:4] has 29 * 3 = 87 elements → Upper minus lower was used without adding 1. It should be (30 - 1 + 1) * (4 - 1 + 1) = 30 * 4 = 120 elements.

Key Term

rows * columns
The total number of elements in a 2D array. Each dimension holds upper - lower + 1 values, so ARRAY[1:3, 1:3] holds 3 * 3 = 9 and ARRAY[1:30, 1:4] holds 30 * 4 = 120.

Fill in the Blanks

1. rows ← 3 columns ← 4 total ← rows * columns
Hint: Type the operator that combines rows and columns to give the total number of elements
2. // ARRAY[1:3, 1:3] holds 3 * 3 = 9 elements
Hint: Type the total number of elements in the 2D array
3. // 30 rows * 4 columns = 120 elements DECLARE Marks : ARRAY[1:30, 1:4] OF INTEGER
Hint: Type the upper bound of the column dimension that makes the total match the comment
4. upper ← 30 lower ← 1 rowCount ← upper - lower + 1
Hint: Type the number added so the count includes both the lower and upper bound
5. DECLARE Board : ARRAY[0:2, 0:3] OF CHAR columns ← 3 - 0 + 1 OUTPUT 3 * columns
Hint: Type the lower bound of the column dimension in the declaration

Spot the Error

Question 1
A // Grid: ARRAY[1:3, 1:3]
B Rows ← 3
C Cols ← 3
D Total ← Rows + Cols
E OUTPUT Total
Line D — The number of elements is rows multiplied by columns, not added. It should be Total ← Rows * Cols, which gives 3 * 3 = 9.
Question 2
A // Seats: ARRAY[1:30, 1:4]
B Rows ← 30 - 1
C Cols ← 4 - 1 + 1
D Total ← Rows * Cols
Line B — Each dimension holds upper - lower + 1 values. The +1 is missing, so Rows would be 29. It should be Rows ← 30 - 1 + 1, which gives 30.
Question 3
A // Marks: ARRAY[1:30, 1:4]
B Rows ← 30
C Cols ← 3
D Total ← Rows * Cols
Line C — The second dimension is 1:4, so it holds 4 - 1 + 1 = 4 columns, not 3. It should be Cols ← 4, giving Total = 30 * 4 = 120.
Question 4
A // Board: ARRAY[1:3, 1:3]
B Rows ← 3 - 1 + 1
C Cols ← 3 - 1 + 1
D Total ← Rows / Cols
E OUTPUT "Total is ", Total
Line D — Dividing rows by columns gives 1, not the number of elements. It should be Total ← Rows * Cols, which gives 9.
Question 5
A Count ← 0 // ARRAY[1:3, 1:3]
B FOR R ← 1 TO 3
C FOR C ← 1 TO 2
D Count ← Count + 1
E NEXT C
F NEXT R
Line C — The inner loop must visit all 3 columns. TO 2 skips the last column, so Count would be 6 instead of 9. It should be FOR C ← 1 TO 3.

Student with a class code? Join your class →