← IGCSE Computer Science Paper 2

Reading a value from an array element

Reading an element: Name[index] in OUTPUT or an expression gives the value stored in that element. Reading only uses the value, so the element stays unchanged.

Understanding Reading a value from an array element in IGCSE Computer Science Paper 2

What it does: Scores[3] is read and its value is copied into Best, so Best now holds the same value as element 3. Name[index] in OUTPUT gives the value stored in that element, so 70 is displayed, not the text Marks[3]. The values in the elements are added: 40 + 55 = 95. The index numbers 1 and 2 are not added. The calculation goes on the right of the arrow. The variable that receives the answer goes on the left.

Common mistakes: Quotes make OUTPUT print the word Total instead of the value stored in the variable. It should be OUTPUT Total, which displays 95. An element is read using square brackets around the index, not round brackets. It should be OUTPUT StudentNames[1].

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
Marks[3] ← 70 and then OUTPUT Marks[3]. What is displayed?
70Marks[3]
Matches
OUTPUT StudentNames(1)
↓
Round brackets are used instead of square brackets. An array element must be read as StudentNames[1].
Applying
Meanings
Term
OUTPUT StudentNames[1]
Meaning
Reading an element: Name[index] in OUTPUT or an expression gives the value stored in that element. Reading only uses the value, so the element stays unchanged.
Practice
DECLARE Marks : ARRAY[1:3] OF INTEGER
Testing
Gaps
OUTPUT [1]
Check Answer
Spots
3Total ← Marks[1] + Marks[2]
4OUTPUT "Total"

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

The 'Star Fox' badge — Frozen 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. Marks[3] ← 70 and then OUTPUT Marks[3]. What is displayed?
A. Marks[3]
B. 70 ✓
Name[index] in OUTPUT gives the value stored in that element, so 70 is displayed, not the text Marks[3].
2. Which line READS a value from an array element?
A. OUTPUT StudentNames[1] ✓
B. StudentNames[1] ← "Ava"
OUTPUT StudentNames[1] uses the stored value. The arrow line writes a new value into the element instead.
3. Marks[1] is 40 and Marks[2] is 55. What is Total after Total ← Marks[1] + Marks[2]?
A. 95 ✓
B. 3
The values in the elements are added: 40 + 55 = 95. The index numbers 1 and 2 are not added.
4. Score ← Marks[2] has just run. Which statement is true?
A. Score now holds a copy of the value in Marks[2] ✓
B. Score now holds the number 2
The index 2 only picks the element. The value stored in that element is copied into Score.
5. Marks[4] is 60. After OUTPUT Marks[4], what is stored in Marks[4]?
A. 0
B. 60 ✓
Reading does not change the element. The value stays at 60 after it is displayed.

Match the Pairs

OUTPUT StudentNames[1] → Displays the value stored in element 1 of the StudentNames array
Total ← Marks[1] + Marks[2] → Reads the values in elements 1 and 2 of Marks, adds them and stores the result in Total
Copying one element into a variable: the value is read from the array and stored in the variable → Best ← Scores[3]
Reading an element does not change it: the element keeps its value after being used → Copy ← Marks[2] OUTPUT Marks[2]
OUTPUT StudentNames(1) → Round brackets are used instead of square brackets. An array element must be read as StudentNames[1].
Marks[1] ← Total → The assignment is the wrong way round. This writes Total into the array element instead of reading the element. To read it, write Total ← Marks[1].

Key Term

OUTPUT StudentNames[1]
Reading an element: Name[index] in OUTPUT or an expression gives the value stored in that element. Reading only uses the value, so the element stays unchanged.

Fill in the Blanks

1. OUTPUT StudentNames[1]
Hint: Type the name of the array whose element is being displayed.
2. OUTPUT StudentNames[1]
Hint: Type the index of the first element, which has a lower bound of one.
3. Total ← Marks[1] + Marks[2]
Hint: Type the operator that adds the two values read from the array.
4. Score ← Marks[3]
Hint: Type the array name so the value in element 3 is copied into the variable.
5. Best ← Marks[2] OUTPUT Best OUTPUT Marks[2]
Hint: Type the index of the element that was copied. Reading it did not change it, so it still holds its value.

Spot the Error

Question 1
A Marks[1] ← 40
B Marks[2] ← 55
C Total ← Marks[1] + Marks[2]
D OUTPUT "Total"
Line D — Quotes make OUTPUT print the word Total instead of the value stored in the variable. It should be OUTPUT Total, which displays 95.
Question 2
A StudentNames[1] ← "Ava"
B OUTPUT StudentNames(1)
C StudentNames[2] ← "Ben"
D OUTPUT StudentNames[2]
Line B — An element is read using square brackets around the index, not round brackets. It should be OUTPUT StudentNames[1].
Question 3
A Score[1] ← 8
B Score[2] ← 6
C Copy ← Score[1]
D OUTPUT Copy[1]
Line D — Copy is an ordinary variable that holds one copied value, not an array, so it has no index. It should be OUTPUT Copy.
Question 4
A Quiz[1] = 7
B Quiz[2] ← 9
C Total ← Quiz[1] + Quiz[2]
D OUTPUT Total
Line A — A value is stored with the assignment arrow ←, not =. Without it, Quiz[1] never holds 7, so the later reads give the wrong total. It should be Quiz[1] ← 7.
Question 5
A StudentNames[1] ← Zara
B StudentNames[2] ← "Omar"
C First ← StudentNames[1]
D OUTPUT First
Line A — Text must be in quotes. Without them Zara is treated as a variable, so the element would not hold the string read later. It should be StudentNames[1] ← "Zara".

Student with a class code? Join your class →