← IGCSE Computer Science Paper 2

Reading and changing array elements

Refers to one element of the array Marks by its index, here 3. You can read it or assign to it, e.g. Marks[3] ← 55. An index outside the array bounds causes an error.

Understanding Reading and changing array elements in IGCSE Computer Science Paper 2

What it does: Marks[3] on the right of ← reads the element at index 3 without changing the array. The array name comes first, then the index in square brackets, then the ← assignment arrow and the new value. Marks[3] is the third element, which is 45. 72 is Marks[2], the second element. Assigning to an element overwrites its old value. The other elements stay where they are and keep their values. The array starts at index 1, so index 0 does not exist. Using an index outside the bounds causes an error. Putting an array element on the left of ← assigns a new value to that one element.

Common mistakes: An element is chosen with square brackets, not round brackets. It should be Marks[3] ← 55. The index variable is spelt Index, but Indx was never given a value. It should be OUTPUT Marks[Index].

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 275–285) and word search (Modules 275–295).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line stores 55 in the third element of the array Marks?
Marks ← 55[3]Marks[3] ← 55
Matches
DECLARE Marks : ARRAY[1:5] OF INTEGER Marks[6] ← 55
↓
Index 6 is outside the bounds 1 to 5, so this causes an error. Use an index from 1 to 5, such as Marks[5].
Applying
Meanings
Term
Marks[3]
Meaning
Refers to one element of the array Marks by its index, here 3. You can read it or assign to it, e.g. Marks[3] ← 55. An index outside the array bounds causes an error.
Practice
DECLARE Marks : ARRAY[1:5] OF INTEGER
Testing
Gaps
Marks[] ← 55
Check Answer
Spots
3Marks[5] ← 64
4Marks(3) ← 55

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

The 'Space Rabbit' badge — Launch Pad, 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 55 in the third element of the array Marks?
A. Marks[3] ← 55 ✓
B. Marks ← 55[3]
The array name comes first, then the index in square brackets, then the ← assignment arrow and the new value.
2. Marks is declared as ARRAY[1:5] OF INTEGER. Which statement causes an error?
A. Marks[5] ← 40
B. Marks[6] ← 40 ✓
The valid indexes are 1 to 5. Index 6 is outside the bounds, so it is an error. Marks[5] is the last valid element.
3. Index ← 4. Which expression refers to the fourth element of Marks?
A. Marks(Index)
B. Marks[Index] ✓
A variable can be used as the index inside square brackets. Cambridge pseudocode uses [ ], not ( ), for array indexes.
4. Marks holds 60, 72, 45, 80, 90 at indexes 1 to 5. What does OUTPUT Marks[3] display?
A. 45 ✓
B. 72
Marks[3] is the third element, which is 45. 72 is Marks[2], the second element.
5. Marks[3] currently holds 45. What happens when Marks[3] ← 55 runs?
A. The 45 is replaced by 55 ✓
B. 55 is inserted and the other values shift along
Assigning to an element overwrites its old value. The other elements stay where they are and keep their values.

Match the Pairs

Marks[3] ← 55 → Changes the element at index 3 of the array Marks to the value 55
OUTPUT Marks[Index] → Displays the element whose position is given by the variable Index
Reading one element: the value stored at index 3 is copied into a variable → Score ← Marks[3]
Using a variable as the index so the same line works on different elements → Marks[Index] ← 0
DECLARE Marks : ARRAY[1:5] OF INTEGER Marks[6] ← 55 → Index 6 is outside the bounds 1 to 5, so this causes an error. Use an index from 1 to 5, such as Marks[5].
Marks(3) ← 55 → Round brackets are used instead of square brackets. The element should be written as Marks[3] ← 55.

Key Term

Marks[3]
Refers to one element of the array Marks by its index, here 3. You can read it or assign to it, e.g. Marks[3] ← 55. An index outside the array bounds causes an error.

Fill in the Blanks

1. // Change the element at index 3 Marks[3] ← 55
Hint: Type the index number of the element being changed, as stated in the comment.
2. DECLARE Marks : ARRAY[1:5] OF INTEGER OUTPUT Marks[3]
Hint: Type the name of the array declared on the line above.
3. Index ← 4 OUTPUT Marks[Index]
Hint: Type the variable that holds the position to read, so the index can change.
4. // Add 5 to element 2 Marks[2] ← Marks[2] + 5
Hint: Type the assignment symbol that stores the new value in the element.
5. DECLARE Marks : ARRAY[1:5] OF INTEGER // Highest valid index is used here Marks[5] ← 70
Hint: Type the highest index allowed by the array's declared bounds, to avoid an out of bounds error.

Spot the Error

Question 1
A // Marks is indexed 1 to 5
B Marks[1] ← 70
C Marks[5] ← 64
D Marks(3) ← 55
E OUTPUT Marks[3]
Line D — An element is chosen with square brackets, not round brackets. It should be Marks[3] ← 55.
Question 2
A // Marks is indexed 1 to 5
B Index ← 2
C Marks[Index] ← 80
D OUTPUT Marks[Indx]
Line D — The index variable is spelt Index, but Indx was never given a value. It should be OUTPUT Marks[Index].
Question 3
A Marks[2] ← 60
B Marks[3] = Marks[2] + 5
C OUTPUT Marks[3]
Line B — Assigning to an element needs the assignment arrow ←, not =. It should be Marks[3] ← Marks[2] + 5.
Question 4
A Marks ← 55
B OUTPUT Marks[3]
C Marks[3] ← Marks[3] + 5
Line A — Marks is the whole array. To store 55 in one element you must give its index, so it should be Marks[3] ← 55.
Question 5
A // Marks is indexed 1 to 5
B FOR Index ← 1 TO 5
C OUTPUT Marks[Index + 1]
D NEXT Index
Line C — When Index is 5, Marks[Index + 1] is Marks[6], which is outside the bounds 1 to 5 and causes an error. It should be OUTPUT Marks[Index].

Student with a class code? Join your class →