O Level Computer Science (2210)

Programming

Variables, constants, data types, and input/output

Store values in variables and constants, choose the right data type, and use INPUT and OUTPUT.

Examples use Cambridge pseudocode for the 2026–2028 syllabus.

Variables are labelled boxes

A variable is a named location in memory that stores a value. The value can change while the program runs. Think of it as a labelled box: the name is on the label, the value is inside.

In pseudocode, declare each variable with its data type, then use <- to put a value into it. Assignment replaces whatever was in the box before.

Pseudocode
DECLARE Score : INTEGER
Score <- 10
Score <- Score + 5
OUTPUT Score

Key idea. Score <- Score + 5 means: take the value in Score, add 5, and put the answer back in Score. It is not an equation.

Constants

A constant is a named value that cannot change while the program runs. Using a constant means the value is written in one place, so it is easy to update and impossible to change by accident.

Pseudocode
CONSTANT VatRate <- 0.2
DECLARE Price : REAL
INPUT Price
OUTPUT "Price with VAT: ", Price * (1 + VatRate)

Data types

Every variable has a data type that sets what it can hold:

TypeHoldsExamples
INTEGERWhole numbers42, -7, 0
REALNumbers with a decimal part3.14, -0.5, 19.99
CHARA single character'A', '7', '?'
STRINGText: zero or more characters"Hello", "07700 900123"
BOOLEANTRUE or FALSETRUE, FALSE

Exam tip. Phone numbers are stored as STRING, not INTEGER: they can start with 0, contain spaces, and you never do maths with them.

Input and output

INPUT waits for the user to type a value and stores it in a variable. OUTPUT displays values. Separate several values with commas.

In PseudoEditor, the terminal asks for each INPUT while the program runs, so you can test interactive programs in the browser.

Pseudocode
DECLARE Name : STRING
DECLARE Age : INTEGER
OUTPUT "What is your name?"
INPUT Name
OUTPUT "How old are you?"
INPUT Age
OUTPUT "Hello ", Name, ", next year you will be ", Age + 1

Sequence

Sequence means statements run one after another, in order, from top to bottom. Changing the order changes the result: in the program above, the age must be input before it is used.

Check yourself

What data type should store whether a door is locked?Show answer

BOOLEAN, since it is either TRUE or FALSE.

What is output by: X <- 4, X <- X * 3, OUTPUT X?Show answer

12.

Give one reason to use a constant instead of typing the value each time.Show answer

If the value changes it only needs updating in one place, and it cannot be changed by mistake while the program runs.

References used to build these lessons

We used these official documents as references when building this course's lessons. They are the sources for the syllabus structure and course requirements.

Cambridge International · 2210 · Exams 2026–2028