← IGCSE Computer Science Paper 2

Choosing a 1D or 2D array for a scenario

Use a 1D array for a simple list of values. Use a 2D array when data forms a table or grid, so each value needs two indexes: a row and a column.

Understanding Choosing a 1D or 2D array for a scenario in IGCSE Computer Science Paper 2

What it does: 30 students by 4 tests is a table with two ways of locating a value, so a 2D array fits. With parallel 1D arrays, index 5 in each array refers to the same student. Each array is still a simple list with one index. Two indexes inside the brackets (student 5, test 2) mean the array is two-dimensional. A game board is a grid, so each square needs two indexes (row and column). That calls for a 2D array. Data needing a row and a column must be stored in a 2D array. A 1D array only accepts one index.

Common mistakes: A list of 30 names is a 1D array, so each name needs only one index. It should be Names[5] ← "Zoe". A game board is a grid, so it is a 2D array and each square needs a row and a column. It should be Board[2,2] ← "X".

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 479–488) and word search (Modules 479–499).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A teacher stores the names of 30 students in one simple list. Which array fits best?
A 2D array, e.g. ARRAY[1:30, 1:30] OF STRINGA 1D array, e.g. ARRAY[1:30] OF STRING
Matches
DECLARE Marks : ARRAY[1:120] OF INTEGER Marks[3, 2] <- 75
↓
The array is 1D but is used with two indexes. Marks for students and tests form a table, so it should be declared as 2D: ARRAY[1:30, 1:4] OF INTEGER.
Applying
Meanings
Term
1D or 2D array
Meaning
Use a 1D array for a simple list of values. Use a 2D array when data forms a table or grid, so each value needs two indexes: a row and a column.
Practice
// 1D: a simple list of names
Testing
Gaps
DECLARE Names : ARRAY[] OF STRING
Check Answer
Spots
1Names[5,1] ← "Zoe"
2Names[6] ← "Leo"

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

The 'Wolverine' badge — Fearless 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 teacher stores the names of 30 students in one simple list. Which array fits best?
A. A 1D array, e.g. ARRAY[1:30] OF STRING ✓
B. A 2D array, e.g. ARRAY[1:30, 1:30] OF STRING
A simple list of names needs only one index to find each name, so a 1D array is the right choice.
2. A noughts and crosses game board has 3 rows and 3 columns. Which array fits best?
A. A 1D array, e.g. ARRAY[1:3] OF CHAR
B. A 2D array, e.g. ARRAY[1:3, 1:3] OF CHAR ✓
A game board is a grid. Each square is found using a row index and a column index, so a 2D array fits.
3. A program stores the marks of 30 students over 4 tests. Which array fits best?
A. One 1D array: ARRAY[1:30] OF INTEGER
B. One 2D array: ARRAY[1:30, 1:4] OF INTEGER ✓
The marks form a table: 30 rows (students) by 4 columns (tests). A 1D array has no way to store the 4 tests per student.
4. Which statement about choosing an array is correct?
A. Use a 2D array when each value needs a row and a column to locate it ✓
B. Use a 2D array whenever you have more than 10 values
The choice depends on the shape of the data, not on how many values there are. 100 names in a list still need only a 1D array.
5. Which array would you use to find a student's mark with Marks[5, 2]?
A. A 2D array, because two indexes are used ✓
B. A 1D array, because it is a list of marks
Two indexes inside the brackets (student 5, test 2) mean the array is two-dimensional.

Match the Pairs

DECLARE Names : ARRAY[1:30] OF STRING → A 1D array: one simple list of 30 names, where each name is found using a single index
DECLARE Board : ARRAY[1:3, 1:3] OF CHAR → A 2D array: a 3 by 3 game board grid, where each square is found using a row and a column
Marks for 30 students over 4 tests form a table, so each mark needs a student (row) and a test (column) → DECLARE Marks : ARRAY[1:30, 1:4] OF INTEGER
Parallel 1D arrays store related lists side by side, and the same index links the matching items → Names[5] <- "Ava" Scores[5] <- 88
DECLARE Marks : ARRAY[1:120] OF INTEGER Marks[3, 2] <- 75 → The array is 1D but is used with two indexes. Marks for students and tests form a table, so it should be declared as 2D: ARRAY[1:30, 1:4] OF INTEGER.
DECLARE Names : ARRAY[1:30, 1:1] OF STRING Names[7, 1] <- "Zoe" → A simple list of names needs only one index, so a 2D array is unnecessary. It should be DECLARE Names : ARRAY[1:30] OF STRING and Names[7] <- "Zoe".

Key Term

1D or 2D array
Use a 1D array for a simple list of values. Use a 2D array when data forms a table or grid, so each value needs two indexes: a row and a column.

Fill in the Blanks

1. DECLARE Names : ARRAY[1:30] OF STRING
Hint: A simple list of 30 names needs only one range. Type the bounds as lower:upper.
2. DECLARE Board : ARRAY[1:3, 1:3] OF CHAR
Hint: A 3 by 3 game board is a grid. Type the bounds for the second dimension (the columns).
3. DECLARE Marks : ARRAY[1:30, 1:4] OF INTEGER
Hint: Marks for 30 students over 4 tests form a table. Type the column bounds, one column for each test.
4. // mark for each student and test OUTPUT Marks[Student, Test]
Hint: Two indexes (student and test) are used, so type the name of the 2D array that holds the table of marks.
5. // parallel 1D arrays share one index OUTPUT Names[I], Marks[I]
Hint: Matching values in parallel arrays sit at the same position. Type the index variable that links them.

Spot the Error

Question 1
A Names[5,1] ← "Zoe"
B Names[6] ← "Leo"
C OUTPUT Names[5]
Line A — A list of 30 names is a 1D array, so each name needs only one index. It should be Names[5] ← "Zoe".
Question 2
A Board[2] ← "X"
B Board[1,3] ← "O"
C OUTPUT Board[2,2]
Line A — A game board is a grid, so it is a 2D array and each square needs a row and a column. It should be Board[2,2] ← "X".
Question 3
A Marks[1,1] ← 72
B Marks[1,2] ← 65
C Marks[2,1] ← 58
D Marks[2] ← 80
Line D — Marks for students across several tests form a table, so a 2D array. You need the student (row) and the test (column): Marks[2,2] ← 80.
Question 4
A Name[3] ← "Mia"
B Mark[4] ← 91
C OUTPUT Name[3], Mark[3]
Line B — With parallel 1D arrays, the same index must be used for the same student. Mia is at index 3 in Name, so her mark must be Mark[3] ← 91.
Question 5
A FOR r ← 1 TO 3
B FOR r ← 1 TO 3
C Board[r,c] ← "-"
D NEXT c
E NEXT r
Line B — A 2D board needs two different loop variables, one for rows and one for columns. The inner loop should be FOR c ← 1 TO 3, because Board[r,c] uses c.

Student with a class code? Join your class →