Declare variables and constants
Give changing data a clear name and protect fixed values with constants.
Exam scope and assessment notes
This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. It covers section 8.1 (Programming concepts) only. Pseudocode examples use the published Cambridge format; the separate 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers, a browser-based programming workspace and human subject-teacher review remain outstanding.
Before you begin
- Be comfortable following an ordered algorithm and tracing variable values. Each lesson introduces the Cambridge pseudocode form it uses.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
What does Score ← 0 do?
What you will learn
- Declare a variable with a suitable data type
- Assign and update a variable
- Use a constant for a fixed literal value
A variable stores a value that may change
Declare a variable before using it, with a meaningful identifier and a data type. Assignment uses the left arrow: Score ← 0. A later assignment can replace the current value, such as Score ← Score + 1.
The identifier stays the same while its stored value can change. Choose a name that tells a reader what the value represents, such as AttemptsRemaining rather than X.
A constant records a fixed literal
Declare a constant with CONSTANT followed by its identifier and a literal value. Constants make rules easier to read and update, such as CONSTANT PassMark ← 50.
The syllabus pseudocode allows only a literal as the value assigned to a constant. Do not define one from a variable or calculation.
Pause and explain
Which is a valid constant declaration?
Worked example
A club charges the same hourly rate for every booking. Show a constant and calculate the charge for three hours.
Show the worked solution
- Store the fixed rate as CONSTANT HourlyRate ← 6.50.
- Declare Hours and Charge as REAL values if fractional amounts are possible.
- Assign Charge ← Hours * HourlyRate.
Answer CONSTANT HourlyRate ← 6.50; Charge ← 3 * HourlyRate, so Charge is 19.50.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
Declare a whole-number variable for a learner's attempts and increase it by one.
Give me a hint
Use an INTEGER and assign the updated value back to the same name.
Compare my reasoning
- Declare Attempts : INTEGER.
- Set Attempts ← 0 before the first attempt.
- After an attempt, set Attempts ← Attempts + 1.
DECLARE Attempts : INTEGER; Attempts ← 0; Attempts ← Attempts + 1.
Look for these in your work
- Meaningful identifier
- Integer declared
- Updated assignment
A game has a fixed maximum score of 100. Show a suitable declaration and explain why it is a constant.
Give me a hint
The maximum does not change during the game.
Compare my reasoning
- Choose a clear name such as MaximumScore.
- Assign the literal 100 with CONSTANT.
- Use that identifier in checks instead of repeating 100.
CONSTANT MaximumScore ← 100, because the allowed maximum is fixed.
Look for these in your work
- Literal assigned
- Fixed value reason
A program uses X for the number of seats booked and later changes it to 4. Improve the identifier and explain what the assignment means.
Give me a hint
Name the value for the data it stores.
Compare my reasoning
- Rename X to SeatsBooked.
- Declare it as an INTEGER.
- Assign SeatsBooked ← 4 to store the current booking count.
Use SeatsBooked : INTEGER and assign SeatsBooked ← 4; the variable holds a value that may change.
Look for these in your work
- Clear identifier
- Suitable type
- Assignment explained
Common mistakes
- Using ← as a comparison instead of assignment
- Changing a value that should be a constant
- Using unclear identifiers such as A or Temp for permanent data
What can you explain now?
What is the main difference between a variable and a constant?
Compare with the explanation
A variable may be reassigned; a constant holds its declared literal
Variables can change as an algorithm runs; constants are fixed values.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
When should a value be declared as a constant rather than a variable?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.