← IGCSE Computer Science Paper 2

Writing a value into an array element

Stores a value in one array element using the assignment operator ←. The value must match the array's data type, and it replaces any old value already in that element.

Understanding Writing a value into an array element in IGCSE Computer Science Paper 2

What it does: Strings are written in double quotes in IGCSE pseudocode, so the value "Blue" is stored in element 2 of a STRING array. In IGCSE pseudocode, the index goes in square brackets and the assignment operator is ←. Round brackets and = are not used for assignment. The value must match the array's data type. An INTEGER array can only store whole numbers, not text. Assigning replaces the old value. An element holds only one value at a time, so "Ali" is overwritten. Name[index] ← value changes just one element. The other elements keep their values.

Common mistakes: Assigning a value to an array element uses the assignment operator ←, not =. It should be StudentNames[3] ← "Cy". A string value must be written in double quotes. Without them, Plum looks like a variable name. It should be Fruit[3] ← "Plum".

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 449–458) and word search (Modules 439–458).

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 string "Ali" in the first element of StudentNames?
StudentNames(1) = "Ali"StudentNames[1] ← "Ali"
Matches
StudentNames[1] ← Ali
↓
The string Ali has no double quotes, so it is read as a variable name instead of text. It should be "Ali".
Applying
Meanings
Term
StudentNames[1] ← "Ali"
Meaning
Stores a value in one array element using the assignment operator ←. The value must match the array's data type, and it replaces any old value already in that element.
Practice
DECLARE StudentNames : ARRAY[1:3] OF STRING
Testing
Gaps
StudentNames[1] "Ali"
Check Answer
Spots
2StudentNames[2] ← "Bea"
3StudentNames[3] = "Cy"

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

The 'Woodland Hedgehog' badge — Import Master, 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 string "Ali" in the first element of StudentNames?
A. StudentNames(1) = "Ali"
B. StudentNames[1] ← "Ali" ✓
In IGCSE pseudocode, the index goes in square brackets and the assignment operator is ←. Round brackets and = are not used for assignment.
2. StudentNames is an ARRAY OF STRING. Which assignment is correct?
A. StudentNames[2] ← "Bea" ✓
B. StudentNames[2] ← Bea
String values must be written in double quotes. Without quotes, Bea would look like a variable name.
3. Scores is an ARRAY[1:5] OF INTEGER. Which assignment matches the data type?
A. Scores[3] ← 85 ✓
B. Scores[3] ← "eighty-five"
The value must match the array's data type. An INTEGER array can only store whole numbers, not text.
4. StudentNames[1] holds "Ali". After StudentNames[1] ← "Sam", what does element 1 hold?
A. "Sam" ✓
B. "Ali" and "Sam"
Assigning replaces the old value. An element holds only one value at a time, so "Ali" is overwritten.
5. Which statement is true about writing to an array element?
A. Every element in the array changes
B. Only the element at the given index changes ✓
Name[index] ← value changes just one element. The other elements keep their values.

Match the Pairs

StudentNames[1] ← "Ali" → Stores the string "Ali" in element 1 of the StudentNames array
Scores[3] ← 50 Scores[3] ← 72 → Element 3 ends up holding 72, because the second assignment replaces the old value 50
A string value written into a STRING array element must be inside double quotes → Colours[2] ← "Blue"
The value must match the array data type, so an INTEGER array element is given a whole number → Marks[4] ← 85
StudentNames[1] ← Ali → The string Ali has no double quotes, so it is read as a variable name instead of text. It should be "Ali".
Marks[2] ← "high" → Marks is an INTEGER array, so a string cannot be stored in it. The value must be a whole number such as 90.

Key Term

StudentNames[1] ← "Ali"
Stores a value in one array element using the assignment operator ←. The value must match the array's data type, and it replaces any old value already in that element.

Fill in the Blanks

1. StudentNames[1] ← "Ali"
Hint: Type the assignment operator that stores the value in the element.
2. DECLARE StudentNames : ARRAY[1:3] OF STRING StudentNames[2] ← "Mia"
Hint: Type the name of the array that the value is stored in.
3. StudentNames[1] ← "Ali" StudentNames[1] ← "Ben"
Hint: Type the index that makes Ben replace the old value Ali.
4. DECLARE Marks : ARRAY[1:5] OF INTEGER Marks[1] ← 85
Hint: Type the data type that matches the whole number stored in the array.
5. DECLARE StudentNames : ARRAY[1:3] OF STRING StudentNames[3] ← "Zoe"
Hint: Type the data type the array needs so that a name in double quotes can be stored.

Spot the Error

Question 1
A StudentNames[1] ← "Ali"
B StudentNames[2] ← "Bea"
C StudentNames[3] = "Cy"
D OUTPUT StudentNames[3]
Line C — Assigning a value to an array element uses the assignment operator ←, not =. It should be StudentNames[3] ← "Cy".
Question 2
A Fruit[1] ← "Apple"
B Fruit[2] ← "Pear"
C Fruit[3] ← Plum
D OUTPUT Fruit[3]
Line C — A string value must be written in double quotes. Without them, Plum looks like a variable name. It should be Fruit[3] ← "Plum".
Question 3
A // Scores holds INTEGER values
B Scores[1] ← 45
C Scores[2] ← "60"
D OUTPUT Scores[2]
Line C — The array holds INTEGER values, so the value must match that data type. "60" is a string. It should be Scores[2] ← 60.
Question 4
A Prices[1] ← 2.5
B Prices(2) ← 3.75
C Prices[3] ← 1.2
Line B — An array index goes in square brackets, not round brackets. It should be Prices[2] ← 3.75.
Question 5
A 21 ← Temp[1]
B Temp[2] ← 19
C OUTPUT Temp[1]
Line A — The array element goes on the left of ← and the value goes on the right. The value is stored in the element. It should be Temp[1] ← 21.

Student with a class code? Join your class →