← IGCSE Computer Science Paper 2

Using an array element

Reads or changes one array element: the array name, then one index in square brackets. The index must be between the array's lower and upper bound. StudentNames[1] ← "Ali" stores a value.

Understanding Using an array element in IGCSE Computer Science Paper 2

What it does: StudentNames is the array name, [3] is the single index, and ← stores the new value "Mia" in that element. The index must be between the lower bound (1) and the upper bound (5). Index 6 is outside the range, so it causes an error. The index goes inside the square brackets and the new value goes on the right of the ← arrow. The index is a position number, not the value.

Common mistakes: An array index goes in square brackets, not round brackets. It should be Names[1] ← "Ali". The array name comes first, then the index in square brackets. It should be Scores[2] ← 15.

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 176–187) and word search (Modules 166–187).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line stores the name Ali in the first element of the array StudentNames?
StudentNames(1) ← "Ali"StudentNames[1] ← "Ali"
Matches
StudentNames[0] ← "Ali" (array declared as ARRAY[1:30])
↓
Index 0 is outside the array's bounds. The lower bound is 1, so the index must be between 1 and 30.
Applying
Meanings
Term
StudentNames[1]
Meaning
Reads or changes one array element: the array name, then one index in square brackets. The index must be between the array's lower and upper bound. StudentNames[1] ← "Ali" stores a value.
Practice
DECLARE StudentNames : ARRAY[1:5] OF STRING
Testing
Gaps
[1] ← "Ali"
Check Answer
Spots
1// Names: ARRAY[1:5]
2Names(1) ← "Ali"

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

The 'Firefly' badge — Night 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. Which line stores the name Ali in the first element of the array StudentNames?
A. StudentNames(1) ← "Ali"
B. StudentNames[1] ← "Ali" ✓
An array element is written with the array name and the index in square brackets, like StudentNames[1]. Round brackets are not used.
2. The array Scores is declared as ARRAY[1:5] OF INTEGER. Which index is valid?
A. Scores[5] ✓
B. Scores[6]
The index must be between the lower bound (1) and the upper bound (5). Index 6 is outside the range, so it causes an error.
3. What does this line do? StudentNames[n + 1] ← StudentNames[n]
A. Copies the value at position n into the next position ✓
B. Adds 1 to every name in the array
The index can be an expression such as n + 1. The value in element n is copied into element n + 1, which is how items are shifted along.
4. Which of these correctly reads one element of the array StudentNames into a variable called First?
A. First ← StudentNames[1] ✓
B. First ← StudentNames
You need the array name and one index to read a single element. The array name alone refers to the whole array, not one element.
5. StudentNames is declared as ARRAY[1:30] OF STRING. Which statement is out of range?
A. StudentNames[30] ← "Zoe"
B. StudentNames[0] ← "Zoe" ✓
The lower bound is 1, so index 0 does not exist. Index 30 is the upper bound, so it is allowed.

Match the Pairs

StudentNames[1] ← "Ali" → Stores the value "Ali" in the element at index 1 of the StudentNames array
StudentNames[n + 1] ← StudentNames[n] → Copies the value at index n into the next element, whose index is n + 1
To change one element of an array, write the array name, one index in square brackets, then ← and the new value → StudentNames[3] ← "Mia"
To read an element, use the array name and one index in square brackets, for example to output it → OUTPUT StudentNames[2]
StudentNames[0] ← "Ali" (array declared as ARRAY[1:30]) → Index 0 is outside the array's bounds. The lower bound is 1, so the index must be between 1 and 30.
StudentNames(1) ← "Ali" → Round brackets are used instead of square brackets. The index must be written in square brackets.

Key Term

StudentNames[1]
Reads or changes one array element: the array name, then one index in square brackets. The index must be between the array's lower and upper bound. StudentNames[1] ← "Ali" stores a value.

Fill in the Blanks

1. StudentNames[1] ← "Ali"
Hint: Type the name of the array whose first element is being set.
2. DECLARE StudentNames : ARRAY[1:5] OF STRING StudentNames[5] ← "Zoe"
Hint: Type the index of the last valid element, which is the upper bound.
3. StudentNames[n + 1] ← StudentNames[n]
Hint: Type the variable used as the index of the element being copied.
4. StudentNames[1] ← "Ali"
Hint: Type the assignment symbol that stores a value in the element.
5. OUTPUT StudentNames[2]
Hint: Type the keyword that displays the value stored in the element.

Spot the Error

Question 1
A // Names: ARRAY[1:5]
B Names(1) ← "Ali"
C OUTPUT Names[1]
Line B — An array index goes in square brackets, not round brackets. It should be Names[1] ← "Ali".
Question 2
A [2]Scores ← 15
B Scores[3] ← Scores[2] + 5
C OUTPUT Scores[3]
Line A — The array name comes first, then the index in square brackets. It should be Scores[2] ← 15.
Question 3
A // Marks: ARRAY[1:10]
B Marks[11] ← 75
C OUTPUT Marks[10]
Line B — The array only goes up to index 10, so index 11 is above the upper bound. It should be Marks[10] ← 75.
Question 4
A // Temp: ARRAY[0:6]
B Temp[0] ← 12
C Temp[7] ← 18
D OUTPUT Temp[6]
Line C — The upper bound of Temp is 6, so index 7 does not exist. It should be Temp[6] ← 18.
Question 5
A // Names: ARRAY[1:5]
B n ← 2
C Names[n + 1] ← Names[n]
D OUTPUT Names[n + 1
Line D — The square bracket is not closed. Every index needs both brackets: OUTPUT Names[n + 1].

Student with a class code? Join your class →