GCSE · Computer Science · AQA · Spec 8525
Subtraction (arithmetic operator)
14 °C at 9 am, 9 °C by 3 pm. Did the temperature change by -5 or by 5? In code, it depends on which number you write first.
Computer Science · Algorithms
Trace table — dry run the code
A weather app stores two temperature readings and works out the change. Before each Next, predict what the line will store. Keep an eye on the swapped line and the one that subtracts from later itself.
Ready when you are — step through one line at a time.
Predict, then check
Two minus signs in one line. Which subtraction happens first?
A program runs this line: left ← 20 - 5 - 3. What number is stored in left?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
The same two numbers can give a rise or a fall. It all depends on which one you write first.
What you need to know
- The subtraction operator (-) takes the second operand away from the first: a - b.
- Operands are the values either side of the operator. In 9 - 14, they are 9 and 14.
- Swap the operands and you get the same size with the opposite sign: 9 - 14 = -5, but 14 - 9 = 5.
Have a goYour friend insists 4 - 10 and 10 - 4 'both come out as 6, obviously'. What does each one actually give?
4 - 10 = -6 and 10 - 4 = 6.
Your friend took the smaller number from the bigger both times. The size matches, but putting the smaller operand first makes the answer negative.
- A negative answer isn't an error. With later - earlier, the minus sign tells you the value fell.
- So decide what the answer should mean first, then choose which operand goes first.
- A chain such as 20 - 5 - 3 is worked left to right: 15 first, then 12.
- Brackets are worked out first, so 20 - (5 - 3) stores 18 instead of 12.
Have a goWork out both lines before you look: 12 - 4 - 2, then 12 - (4 - 2).
6, then 10.
Left to right gives 12 - 4 = 8, then 8 - 2 = 6. The bracket goes first in the second line: 4 - 2 = 2, then 12 - 2 = 10. Starting from the right gives 10 for both.
- The result must be stored (assigned to a variable) if the program needs it later.
- x ← x - 1 updates x: its current value is used, then the answer replaces it.
Have a gocoins holds 5. The line coins ← coins - 2 runs twice. What does coins hold after the second run?
1
Each run starts from the value coins holds right then: 5 - 2 = 3, then 3 - 2 = 1. It doesn't restart from 5, and it isn't set to -2.
- A stored result stays put. If a value it used changes afterwards, the result only changes when that line runs again.
The big picture
The subtraction operator (-) takes the second value away from the first. The values either side of it are called operands, and their order matters: 9 - 14 is -5, but 14 - 9 is 5. Same size, opposite sign. A chain like 20 - 5 - 3 is worked left to right, and brackets change that order. The answer only survives if it is stored, and a line like later ← later - 2 updates a variable using its own current value.
Key points
Worked example
Problem
A car park program starts with spaces ← 150. Then these lines run in order: spaces ← spaces - 40, then spaces ← spaces - 25, then taken ← 150 - spaces. What values are stored in spaces and taken at the end?
⚠ Watch out
Writing the operands the wrong way round, e.g. earlier - later when you meant later - earlier. The answer has the right size and the wrong sign, so it's easy to miss. Decide what the answer should mean first, then choose the order.
Memory hook
First minus second, exactly as written. Swap them and the sign flips.
Check yourself
These lines run in order: a ← 10, b ← 25, a ← a - b. What does a hold now? (Answer: -15. 10 - 25 = -15, and that replaces the 10.)
Flashcards
(8)What does the subtraction operator (-) do in a program?
What are the operands of a subtraction?
Does a - b give the same answer as b - a?
How is 30 - 10 - 4 worked out?
What do the brackets do in 30 - (10 - 4)?
What does score ← score - 5 do?
Why should the result of a subtraction be assigned to a variable?
What does a negative result from later - earlier tell you?
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 7 November 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.