Working out how many elements an array holds
The number of elements in a 1D array: upper bound minus lower bound plus one. ARRAY[0:9] holds 9 - 0 + 1 = 10 elements, and ARRAY[5:9] holds 5.
Understanding Working out how many elements an array holds in IGCSE Computer Science Paper 2
What it does: Counting from 0, indexes 0 to 9 give 9 - 0 + 1 = 10 elements, so the upper bound is one less than the size. For ARRAY[1:30] the calculation 30 - 1 + 1 gives 30, which is the size of the array. 30 - 1 + 1 = 30. Always add the 1 back after subtracting the bounds. 9 - 0 + 1 = 10. Index 0 counts as an element, so there are 10 and not 9. Subtracting the bounds misses one element. The bounds are both included, so you must add 1. ARRAY[0:20] holds 20 - 0 + 1 = 21. ARRAY[5:24] holds 24 - 5 + 1 = 20.
Common mistakes: The number of elements is upper - lower + 1, not upper + lower + 1. It should be Size ← 30 - 1 + 1, which gives 30. The lower bound has been subtracted from the upper bound the wrong way round, giving a negative number. It should be Size ← Upper - Lower + 1, which gives 10.
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
upper - lower + 1Fill in the Blanks
Spot the Error
Student with a class code? Join your class →