Using a variable as an array index
A variable inside the brackets picks the element whose index matches its value. Change Index (an INTEGER) and the same statement reaches a different element of Marks.
Understanding Using a variable as an array index in IGCSE Computer Science Paper 2
What it does: The statement OUTPUT Marks[Index] is identical both times, but it shows element 2 first and element 5 second because Index has changed. An index is a whole number position, so the variable placed inside the square brackets is declared as INTEGER. Changing the variable changes which element the same statement reaches. Quotes turn Index into text. A variable must be written without quotes so its value is used.
Common mistakes: A variable used as an array index must be an INTEGER. Index is declared as STRING here. It should be DECLARE Index : INTEGER. Array indexes go inside square brackets, not round brackets. It should be Marks[Index + 1] ← 70.
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
Marks[Index]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →