A variable is a named memory location that holds a value which can change during the program's execution. A constant is a named value that cannot change.
In Cambridge pseudocode, assignment uses the ← arrow:
score ← 0 // variable — can change PI ← 3.14159 // constant — should not change name ← "Alice"
totalScore not x)Every variable has a data type that determines what kind of value it can hold and what operations can be performed on it.
| Data Type | Description | Example |
|---|---|---|
| INTEGER | Whole numbers (positive, negative, or zero) | 42, -7, 0 |
| REAL | Numbers with a decimal point | 3.14, -0.5, 100.0 |
| CHAR | A single character | 'A', '3', '!' |
| STRING | A sequence of characters | "Hello", "CS0478" |
| BOOLEAN | Logical value — TRUE or FALSE only | TRUE, FALSE |
Programs communicate with users through input (data coming in) and output (data going out).
// Input — get a value from the user: INPUT name INPUT score // Output — display a value or message: OUTPUT "Enter your name: " OUTPUT "Hello, ", name OUTPUT score
name ← "Alice" score ← 95 OUTPUT "Player: ", name OUTPUT "Score: ", score OUTPUT "Player: " & name & " scored " & score
Sometimes you need to convert between data types. Cambridge pseudocode uses built-in functions:
| Function | Converts to | Example |
|---|---|---|
INT(x) | INTEGER | INT(3.7) returns 3 |
REAL(x) | REAL | REAL(5) returns 5.0 |
STRING(x) | STRING | STRING(42) returns "42" |
CHAR_TO_NUM(c) | INTEGER (ASCII code) | CHAR_TO_NUM('A') returns 65 |
NUM_TO_CHAR(n) | CHARACTER | NUM_TO_CHAR(65) returns 'A' |
In some Cambridge mark schemes you may see variable declarations:
DECLARE score : INTEGER DECLARE name : STRING DECLARE temperature : REAL DECLARE active : BOOLEAN
5 questions · 12 marks
| Term | Definition |
|---|
10 minutes · mixed marks