GCSE · Computer Science · AQA · Spec 8525
Variable declaration
Every game keeps score in a named spot in memory. Win points, and the old number is thrown out as a new one takes its place. That's a variable.
Computer Science · Algorithms
Trace table — dry run the code
Illustrative code, not any one language. Before each Next, read the line about to run and predict: what kind of statement is it, and what will total_score hold afterwards?
Ready when you are — step through one line at a time.
Computer Science · Programming
Declaration, initialisation or later assignment?
A step-counting app uses these statements. Sort each one: is it a declaration, an initialisation or a later assignment?
Still to sort
Declaration (0)
Introduces the name, plus the data type if the language needs one. No value yet.
Where the line is: A declaration names a variable without storing anything in it. As soon as a value is stored, you're looking at an assignment.
Initialisation (0)
The first value the variable ever receives.
Where the line is: Initialisation is an assignment: the first one. It can look exactly like a later assignment. What decides it is whether the variable already held a value.
Later assignment (0)
Gives a new value to a variable that already holds one.
Where the line is: The new value replaces the old one completely. The old value isn't added to or kept anywhere.
The code is illustrative. The note under each statement tells you where it sits in its program, and that can change the answer.
Predict, then check
Both lines run exactly the same way. Cover line B with your hand first.
Line A: t ← p * q. Line B: total_cost ← price * quantity. Reading line A on its own, what can you tell about what it calculates?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Name it, fill it, fill it again. That's what makes it a variable.
What you need to know
- A variable is a location in memory, identified by an identifier, that stores a value which can change while the program runs.
- Declaring a variable introduces its identifier and, in languages that require it, its data type, so memory can be set aside before it is used.
- Assignment gives a variable a value. The first value is its initialisation; every later assignment replaces the value it held.
- Some languages require every variable to be declared with its data type before use. Others, such as Python, create the variable the first time a value is assigned to it.
- A constant is also referred to by an identifier, but it is declared with a value that cannot change while the program runs.
- Give variables meaningful identifiers that describe what they store, such as total_score rather than x, so code is easier to read and maintain.
The big picture
A variable is a named location in memory that stores a value, and that value can change while the program runs. Declaring a variable introduces its identifier, plus a data type in languages that need one. Giving it its first value is initialisation, and each later assignment replaces the value it held. Some languages require a declaration first; Python creates a variable the first time a value is assigned to it. A constant also has an identifier, but its value cannot change while the program runs. Meaningful identifiers make code easier to read and maintain.
Key points
Worked example
Problem
Here is some illustrative code for a game. Line 1: constant START_LIVES ← 3. Line 2: integer lives. Line 3: lives ← START_LIVES. Line 4: lives ← lives - 1. Line 5: lives ← lives + 2. For lines 2 to 5, say which kind of statement each one is, and give the value of lives after it runs.
⚠ Watch out
Calling every line that mentions a variable a 'declaration'. A declaration only introduces the name (and data type, if the language needs one). The line giving the first value is the initialisation; any later line giving a new value is a later assignment, replacing what was there.
Memory hook
Name it, fill it, refill it. Declaring labels the box, initialising puts the first value in, and every later assignment tips the old value out before the new one goes in. A constant is a box with its lid glued shut.
Check yourself
Without looking back: name the three kinds of statement a variable can meet during a program, say what each one does, and explain which of the three a constant can never meet.
Flashcards
(10)What is a variable?
What does declaring a variable do?
What is initialisation?
A later assignment gives a variable a new value. What happens to the old one?
How do you work out total_score ← total_score + 30?
What is an identifier?
How is a constant different from a variable?
Does every language need variables declared before use?
In Python, what two jobs does total = 0 do if total doesn't exist yet?
Why use meaningful identifiers?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.