In simple terms
A friendly intro before the formal notes — no formulas yet.
Programming's Building Blocks
Learn how to create the fundamental elements of any program: variables and constants. We'll see how to give data a name and a type, and how to store and change values as your program runs.
Imagine you're organising a kitchen. You get different types of containers for different ingredients. An open jar you can refill is a 'variable' (like for sugar). A sealed, printed spice jar with a fixed ingredient is a 'constant' (like 'Salt'). The type of ingredient (granules, liquid, leaf) is the 'data type'. Programming is just organising data in named containers so you can work with it.
- 1
First, identify the pieces of information your program needs to store, like a player's score or a fixed tax rate.
- 2
For each piece of data, choose the most appropriate data type, such as INTEGER for a whole number or STRING for text.
- 3
Declare a named container (a variable or constant) in your code, specifying its name and data type.
- 4
Use the assignment operator to place an initial value into your declared variable or constant.
Explore the concept
Use the live diagram and synced steps — play it or tap a step card to walk through.
Key formulas
Tap any symbol to reveal exactly what it means and its units.
Full topic notes
Formal explanation with the rigour you need for the exam.
Identifiers, Variables, and Constants
At its core, a computer program manipulates data. To do this effectively, we need to give our data meaningful names. These names are called identifiers. Think of them as labels for storage boxes in the computer's memory.
Variable: A named memory location whose value can change while the program is running. Use a variable for things like a user's score, their current input, or a counter in a loop.
Constant: A named memory location whose value is set once and cannot be changed. Use a constant for values that must remain fixed, such as the rate of VAT, the value of Pi, or a game's maximum number of lives.
Identifier Rules: Good practice, and often a requirement, is to use meaningful names (e.g., PlayerScore instead of ). Identifiers cannot contain spaces and usually cannot start with a number.
Declaration and Assignment
Before you can use a variable or constant, you must first create it. This process is called declaration. Declaration tells the program the identifier (name) and the data type of the item you are creating. Once declared, you can give it a value using assignment.
// Declaration Syntax DECLARE <Identifier> : <DataType> CONSTANT <Identifier> = <Value> // Note: Constants are assigned at declaration
// Assignment Syntax <Identifier> <- <Value>
In your Paper 2 exam, you MUST declare all variables you use. A common mistake is to forget declarations, which will lose you marks. Also, be very careful to use for assignment and for comparison. Mixing these up is a frequent error.
The Five Fundamental Data Types
Choosing the correct data type is crucial for efficiency and preventing errors. Cambridge specifies five main types you must know.
INTEGER: Whole numbers (e.g., -10, 0, 150). Used for counting, scores, etc.
REAL: Numbers with a decimal point (e.g., 9.81, 0.20, -12.5). Used for measurements, prices, percentages.
CHAR: A single character (e.g., 'A', '%', '5'). Used for initials, grades (A, B, C), or single-character commands.
STRING: A sequence of characters (e.g., "Cambridge", "user123"). Used for names, addresses, passwords.
BOOLEAN: Represents logical values. Can only be TRUE or FALSE. Used for flags, status checks (e.g., IsLoggedIn, GameOver).
Worked examples
See the formulas applied — reveal one step at a time, like the exam.
A program needs to store a student's name, their score in a test out of 100, and whether they have passed. The pass mark is fixed at 50. Write pseudocode to declare appropriate variables and a constant, and then assign the following example values: Name is 'Ben', score is 78, and they have passed.
- 1
// 1. Declare the constant for the pass mark CONSTANT PassMark : INTEGER = 50
A program for a small shop needs to calculate the final price of an item. It must store the item's name, its price before tax, the VAT rate (fixed at 20%), and the final calculated price. Write pseudocode to declare these, and then calculate the final price for an item named "USB Cable" that costs £5.50 before tax.
- 1
// 1. Declare the constant for the VAT rate CONSTANT VAT_RATE : REAL = 0.20
How it all connects
The big idea sits in the middle — tap a linked idea to explore the link.
Tap a linked idea to see how it connects back to the main topic — that connection is what examiners reward.
Glossary
Try to recall each definition before you reveal it.
Quick check
Answer in your head first — then tap to check. No pressure.
Revision flashcards
Flip the card. Test yourself before the exam.
What is an identifier?
A name given by a programmer to a variable, constant, procedure, or function. It must be unique and follow specific naming rules (e.g., no spaces, cannot start with a number).
Key takeaways
Review these before you close the topic — retrieval beats re-reading.
- ✓
Variable: A named memory location whose value can change while the program is running. Use a variable for things like a user's score, their current input, or a counter in a loop.
- ✓
Constant: A named memory location whose value is set once and cannot be changed. Use a constant for values that must remain fixed, such as the rate of VAT, the value of Pi, or a game's maximum number of lives.
- ✓
Identifier Rules: Good practice, and often a requirement, is to use meaningful names (e.g., PlayerScore instead of ). Identifiers cannot contain spaces and usually cannot start with a number.
Practice — then mark it
The whole point: a real Cambridge question, marked mark-by-mark.
Test Your Knowledge on Programming Basics
Test Your Knowledge on Programming Basics
Extra simulations & links
PhET, GeoGebra and other curated tools — open in a new tab.
Frequently asked
Checkpoint
One marked question is worth ten re-reads — close the loop before you move on.
Reading it isn’t knowing it — prove it.
Before you move on: do Test Your Knowledge on Programming Basics on paper, snap a photo, and get examiner-style feedback on exactly where you win and lose marks.