Using an expression as an array index
An index can be an expression like n+1. The expression is worked out first, then that element is used. It must stay within the array's bounds. Example: n=3 gives Array[4].
Understanding Using an expression as an array index in IGCSE Computer Science Paper 2
What it does: The index n + 1 on the left is worked out first, so the value from position n is stored in the next element. The upper bound is 10, so the check n + 1 <= 10 makes sure the calculated index is valid before the element is used. n-1 is worked out as 5 - 1 = 4, so it gives the element before element 5. 1 - 1 = 0, but the lowest valid index is 1, so the index is out of range. If n is 10, then n+1 is 11, which is out of range. Checking n < 10 means n+1 is at most 10.
Common mistakes: To copy a value to the NEXT element the index must be n+1. n-1 is the previous element (2), so the value goes to the wrong place and Names[4] is not set. It should be Names[n+1] ← Names[n]. The previous element is found with n-1. n+1 gives the next element (6), not the previous one. It should be previous ← Score[n-1].
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
Array[n+1]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →