← IGCSE Computer Science Paper 2

What a variable is

A named storage location in memory whose value can change while a program runs, such as Score going from 0 to 10. Programs use it to remember values.

Understanding What a variable is in IGCSE Computer Science Paper 2

What it does: DECLARE creates the name Score for a memory location that will hold an INTEGER. The stored value is replaced by a new one, so the variable remembers an updated score. A variable's value can change as the program runs. A storage location whose value is fixed is a constant. A variable holds one value at a time. Assigning 10 replaces the old value of 0. Variables use memory to store values the program needs later, such as scores, names or totals. The new assignment replaces the old value, so Lives is now 2. The student thinks the first value is kept, but assigning a new value overwrites the old one.

Common mistakes: The variable name must be on the left of ←, because the value is stored into the variable. A number cannot be a storage location. It should be Score ← 10. A new value is stored in a variable with the assignment arrow ←, not =. It should be Lives ← Lives - 1, which replaces 3 with 2.

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 307–316) and word search (Modules 296–316).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which statement describes a variable?
A named storage location whose value can change while the program runsA named storage location whose value can never change once set
Matches
Score ← 0 Score ← 10 // Score is still 0 now
↓
Wrong: after Score ← 10 the old value is gone. Score now holds 10, because a variable's value can be replaced.
Applying
Meanings
Term
variable
Meaning
A named storage location in memory whose value can change while a program runs, such as Score going from 0 to 10. Programs use it to remember values.
Practice
DECLARE Score : INTEGER
Testing
Gaps
← 10
Check Answer
Spots
3OUTPUT Score
410 ← Score

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

The 'Silverback Gorilla' badge — Savannah 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. Which statement describes a variable?
A. A named storage location whose value can change while the program runs ✓
B. A named storage location whose value can never change once set
A variable's value can change as the program runs. A storage location whose value is fixed is a constant.
2. A program sets Score ← 0 and later Score ← 10. What is true about Score?
A. It now holds both 0 and 10 at the same time
B. Its value changed from 0 to 10, so it is a variable ✓
A variable holds one value at a time. Assigning 10 replaces the old value of 0.
3. What does the name of a variable, such as Score, do?
A. It is the value that is stored in memory
B. It labels a place in memory where a value is stored ✓
The name is a label for a memory location. The value is the data kept in that location.
4. Why do programs use variables?
A. To remember values such as a player's score while the program runs ✓
B. To make the program run without using any memory
Variables use memory to store values the program needs later, such as scores, names or totals.
5. Lives ← 3 is followed by Lives ← 2. What is the value of Lives afterwards?
A. 2 ✓
B. 3
The new assignment replaces the old value, so Lives is now 2.

Match the Pairs

Score ← 0 → Stores the value 0 in the variable Score, so the program remembers the starting score
Score ← 10 → Replaces the old value of Score with 10, showing that a variable's value can change
A variable is a name that labels a place in memory where a value is kept → DECLARE Score : INTEGER
A program can change the value held in a variable while it runs → Score ← Score + 5
Score ← 0 Score ← 10 // Score is still 0 now → Wrong: after Score ← 10 the old value is gone. Score now holds 10, because a variable's value can be replaced.
// A variable's value can never change once it is set Score ← 0 → Wrong: a variable's value can change while the program runs. It is a constant whose value cannot change.

Key Term

variable
A named storage location in memory whose value can change while a program runs, such as Score going from 0 to 10. Programs use it to remember values.

Fill in the Blanks

1. Score ← 0 Score ← 10 OUTPUT Score
Hint: Type the variable name that is being given a new value on line 2.
2. Lives ← 3 Lives ← 2 OUTPUT Lives
Hint: Type the assignment operator that stores a value in the variable.
3. Score ← 0 Score ← 10 OUTPUT Score
Hint: Type the whole number Score should hold after it grows from zero to ten.
4. Level ← 1 Level ← 2 OUTPUT Level
Hint: Type the keyword that displays the variable's current value.
5. Lives ← 3 Lives ← 2 OUTPUT Lives
Hint: Type the variable name whose current value is displayed.

Spot the Error

Question 1
A DECLARE Score : INTEGER
B Score ← 0
C OUTPUT Score
D 10 ← Score
E OUTPUT Score
Line D — The variable name must be on the left of ←, because the value is stored into the variable. A number cannot be a storage location. It should be Score ← 10.
Question 2
A DECLARE Lives : INTEGER
B Lives ← 3
C Lives = Lives - 1
D OUTPUT Lives
Line C — A new value is stored in a variable with the assignment arrow ←, not =. It should be Lives ← Lives - 1, which replaces 3 with 2.
Question 3
A DECLARE Score : INTEGER
B Score 0
C Score ← 10
D OUTPUT Score
Line B — A value is stored in a variable using the assignment operator ←. Without it, the variable is never given its starting value. It should be Score ← 0.
Question 4
A DECLARE Age : INTEGER
B Age ← 14
C OUTPUT Age
D Agee ← 15
E OUTPUT Age
Line D — Agee is a different name from Age and was never declared. The value of the variable Age would not change. It should be Age ← 15.
Question 5
A DECLARE Name : STRING
B Name ← "Sam"
C Name ← Alex
D OUTPUT Name
Line C — Text values must be in double quotes. Without quotes, Alex looks like another variable name. It should be Name ← "Alex".

Student with a class code? Join your class →