← IGCSE Computer Science Paper 2

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.

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
How many elements does ARRAY[1:30] hold?
2930
Matches
ARRAY[0:9] holds 9 elements because 9 - 0 = 9
↓
This forgets to add 1. The correct calculation is 9 - 0 + 1 = 10 elements.
Applying
Meanings
Term
upper - lower + 1
Meaning
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.
Practice
DECLARE Scores : ARRAY[0:9] OF INTEGER
Testing
Gaps
Elements ← 9 - 0 +
Check Answer
Spots
1// Marks : ARRAY[1:30]
2Size ← 30 + 1 + 1

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

The 'Hedgehog' badge — First Steps, 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. How many elements does ARRAY[1:30] hold?
A. 29
B. 30 ✓
30 - 1 + 1 = 30. Always add the 1 back after subtracting the bounds.
2. How many elements does ARRAY[0:9] hold?
A. 10 ✓
B. 9
9 - 0 + 1 = 10. Index 0 counts as an element, so there are 10 and not 9.
3. Which formula gives the number of elements in a 1D array?
A. upper - lower
B. upper - lower + 1 ✓
Subtracting the bounds misses one element. The bounds are both included, so you must add 1.
4. How many elements does ARRAY[5:9] hold?
A. 5 ✓
B. 9
9 - 5 + 1 = 5. The elements are at indexes 5, 6, 7, 8 and 9. The upper bound is not the size.
5. An array needs to hold 10 values and starts at index 0. Which declaration is correct?
A. ARRAY[0:9] OF INTEGER ✓
B. ARRAY[0:10] OF INTEGER
A lower bound of 0 means the upper bound is one less than the size. ARRAY[0:10] would hold 11 elements.

Match the Pairs

ARRAY[1:30] OF STRING → Holds 30 elements, because 30 - 1 + 1 = 30
ARRAY[5:9] OF INTEGER → Holds 5 elements (indexes 5, 6, 7, 8 and 9)
A lower bound of 0 means the size is one more than the upper bound, so an array with 10 elements ends at index 9 → DECLARE Scores : ARRAY[0:9] OF INTEGER
The number of elements is the upper bound minus the lower bound plus one → Size <- 30 - 1 + 1
ARRAY[0:9] holds 9 elements because 9 - 0 = 9 → This forgets to add 1. The correct calculation is 9 - 0 + 1 = 10 elements.
ARRAY[5:9] holds 9 elements because the upper bound is 9 → The upper bound is not the size when the lower bound is not 1. The correct size is 9 - 5 + 1 = 5 elements.

Key Term

upper - lower + 1
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.

Fill in the Blanks

1. // ARRAY[0:9] Elements ← 9 - 0 + 1
Hint: Type the number added after the lower bound is subtracted from the upper bound.
2. Size ← upper - lower + 1
Hint: Type the name of the bound that the lower bound is subtracted from.
3. Size ← 9 - 5 + 1 // ARRAY[5:9] holds 5 elements
Hint: Type the operator that takes the lower bound away from the upper bound.
4. DECLARE Scores : ARRAY[5:9] OF INTEGER // holds 5 elements
Hint: Type the upper bound that gives 5 elements when the lower bound is 5.
5. DECLARE Names : ARRAY[0:29] OF STRING // holds 30 elements
Hint: Type the upper bound, which is one less than the size when counting from zero.

Spot the Error

Question 1
A // Marks : ARRAY[1:30]
B Size ← 30 + 1 + 1
C OUTPUT Size
Line B — The number of elements is upper - lower + 1, not upper + lower + 1. It should be Size ← 30 - 1 + 1, which gives 30.
Question 2
A Lower ← 0
B Upper ← 9
C Size ← Lower - Upper + 1
D OUTPUT Size
Line C — 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.
Question 3
A // Temps : ARRAY[5:9]
B Lower ← 5
C Upper ← 9
D Size ← Upper - Lower - 1
E OUTPUT Size
Line D — You must add 1, not subtract it, because both the lower and upper bound positions count. It should be Size ← Upper - Lower + 1, which gives 5.
Question 4
A Size ← 9 - 0
B // ARRAY[0:9] holds Size items
C OUTPUT Size
Line A — The + 1 is missing, so the program gives 9 instead of 10. Both bounds are elements, so it should be Size ← 9 - 0 + 1.
Question 5
A // Scores : ARRAY[0:19]
B Lower ← 0
C Upper ← 19
D Size ← Upper - Lower
E OUTPUT Size
Line D — Leaving out + 1 gives 19, but ARRAY[0:19] holds 20 elements. The upper bound is one less than the size when the lower bound is 0. It should be Size ← Upper - Lower + 1.

Student with a class code? Join your class →