GCSE · Computer Science · AQA · Spec 8525
Variable declaration
Every game keeps your score somewhere. Win points and the old number gets swapped for a new one. That named, changeable spot in memory? It'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 call it: 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: declaration, initialisation or 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. The moment a value gets stored, you're looking at an assignment instead.
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, and it isn't kept anywhere.
The code is illustrative. Read the note under each statement: where it sits in its program 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 named location in memory that stores a value, and that value can change while the program runs.
- That name is the variable's identifier. The program uses it every time it reads or changes the value.
- Declaring a variable introduces its identifier and, in languages that require it, its data type.
- The declaration comes first so memory can be set aside for the variable before it's used.
- Assignment gives a variable a value. The very first value it gets is called initialisation.
- Each later assignment replaces the value the variable held. The old value isn't added to or kept.
Have a goYour mate is sure of it: 'lives held 3, then lives ← 5 ran, so lives is now 8.' What does lives actually hold?
5
Assignment replaces the value. Your mate added the new value on top of the old one, but the 3 is simply swapped out for 5.
- Some languages require every variable to be declared with its data type before it's used.
- Others, such as Python, create the variable the first time a value is assigned to it.
Have a goProgram A: integer speed, then speed ← 40. Program B: just speed ← 40. Which one would a language that requires declarations refuse to accept?
Program B: speed was never declared.
In that kind of language every variable needs a declaration before use. B would only be fine in a language like Python, which creates speed on its first assignment.
- A constant is also referred to by an identifier, but it's declared with a value that cannot change while the program runs.
Have a goMAX_LIVES is a constant set to 5. Halfway through the game, a line tries MAX_LIVES ← 6. Allowed or not?
Not allowed.
Having an identifier doesn't make it a variable. A constant's value can't change while the program runs; reading it is fine, assigning to it isn't.
- Choose meaningful identifiers, like total_score rather than x, so your 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 its data type in languages that need one, so memory can be set aside before it's used. 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's 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 the 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 drops the first value in, and every later assignment tips the old value out before the new one goes in. A constant? That's 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 28 October 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.