3.1 What is a Variable?
A variable is a named storage location in a computer's memory that holds a value which can change while a program runs. Think of it as a labelled box — the label is the variable's name, and the contents are the value currently stored inside.
Key idea: The name of a variable stays the same, but the value inside it can change as the program runs. That's why it's called a variable!
Why do we use variables?
- To store user input or calculated results for later use
- To reuse values without re-typing them every time
- To make code readable by giving meaningful names to data
- To allow a program to react to changing data at run time
Here's a tiny example that stores and uses a value:
DECLARE Age : INTEGER
Age <- 15
OUTPUT "You are " + Age + " years old."What is a Variable?
3.2 Declaring Variables
Before you can use a variable, you have to declare it. In CIE pseudocode this is done with the DECLARE keyword followed by the variable's name, a colon, and its data type.
Syntax
DECLARE <Name> : <Type>Examples
DECLARE Score : INTEGER
DECLARE Price : REAL
DECLARE UserName : STRING
DECLARE IsReady : BOOLEANAfter a variable is declared, you can give it a value using the assignment operator <-:
DECLARE Score : INTEGER
Score <- 100
OUTPUT ScoreRemember: Declaring a variable only creates the "box". It does not put anything inside — you must assign a value before using it.
Declaring & Assigning Variables
3.3 Data Types
A data type tells the computer what kind of value a variable will hold. Choosing the right type keeps your program correct and efficient. These are the data types used in CIE pseudocode:
| Type | Stores | Example |
|---|---|---|
| INTEGER | Whole numbers | 42, -7, 0 |
| REAL | Numbers with decimals | 3.14, -0.5 |
| STRING | Text (in quotes) | "Hello", "Bob" |
| CHAR | A single character | 'A', '7' |
| BOOLEAN | True or False only | TRUE, FALSE |
| ARRAY | A collection of values | [1, 2, 3, 4] |
DECLARE Age : INTEGER
DECLARE Temperature : REAL
DECLARE FirstName : STRING
DECLARE Initial : CHAR
DECLARE IsLoggedIn : BOOLEANTip: Picking the right type matters! Storing an age as a STRING would stop you doing maths with it. Storing a price as an INTEGER would lose the decimal part.
Data Types
3.4 Variable Naming Rules
Good variable names make your code easy to read and understand. CIE pseudocode (like most languages) has rules about what is and isn't allowed as a variable name.
The Rules
Valid vs Invalid Examples
Valid
- Total_Score
- Age
- StudentName
- Price1
Invalid
- 2ndPlace (starts with digit)
- Student Name (has space)
- OUTPUT (keyword)
- Total-Score (hyphen not allowed)
Variable Naming Rules
3.5 Constants
A constant is like a variable, but its value is set once when the program is written and can never change while the program runs. Use constants for values that should stay the same — like tax rates, conversion factors, or settings.
Syntax
CONSTANT <Name> <- <Value>Examples
CONSTANT PI <- 3.14159
CONSTANT VAT_RATE <- 0.20
CONSTANT MAX_USERS <- 100
OUTPUT "Circumference: " + 2 * PI * RadiusWhy use constants? If you ever need to change a value (say VAT goes from 20% to 22%), you only need to change it in one place. The rest of your code automatically uses the new value.
Variable vs Constant
| Feature | Variable | Constant |
|---|---|---|
| Keyword | DECLARE | CONSTANT |
| Type needed? | Yes (e.g. INTEGER) | No — inferred from value |
| Value can change? | Yes, any time | No — fixed forever |
| Example use | User input, counters | PI, tax rate, MAX_SIZE |
Constants
3.6 Key Points Summary
Let's recap the most important ideas from this topic before you tackle the Question Bank.
Exam tip: In CIE exams, always write pseudocode with UPPERCASE keywords (DECLARE, OUTPUT, IF...) and use the <- arrow for assignment. Examiners deduct marks for using = instead of <-.