Variables, constants and data types Cambridge IGCSE Computer Science (9–1) revision
Not started
Learn it
In plain words
A program has to remember things as it runs: a score, a name, whether the game is over. Each is kept in a named place in memory. If the value may change, the place is a variable. If it must never change, it is a constant.
Every one has a data type, which says what kind of value it holds and so what can be done with it.
6 things to know
- A variable is a named store in memory whose value can change while the program runs. A constant is a named store whose value cannot change while the program runs.
- Declaring a variable: DECLARE Age : INTEGER. Declaring a constant: CONSTANT TaxRate ← 0.2.
- INTEGER: a whole number, such as 17 or −3. REAL: a number with a fractional part, such as 3.75.
- CHAR: a single character, such as 'M'. STRING: a sequence of characters, such as "Hello". BOOLEAN: TRUE or FALSE.
- Assignment gives a variable a value: Age ← 16. INPUT Name reads a value from the user. OUTPUT "Hello ", Name displays text and a value.
- Give every variable and constant a meaningful name, such as TotalCost, not T.
Worked example
A program stores a person's name, age, height in metres, and whether they hold a ticket. Choose a data type for each.
- The name is a sequence of characters: STRING.
- The age is a whole number: INTEGER.
- The height, such as 1.62, has a fractional part: REAL.
- Holding a ticket is yes or no: BOOLEAN.
Tips and tricks
- A phone number is a STRING, not an INTEGER. No arithmetic is done with it, and as a number it would lose its leading zero.
- A constant makes a program easier to maintain: if the value changes, it is changed in one place only.
It lands in your notebook with its questions as flashcards.
Variables, constants and data types: 6 questions and answers
These are the quiz’s questions. Do the quiz first, then come back here for the ones that got you.
Which data type would store the value 3.14?
It has a fractional part.
Which data type stores only TRUE or FALSE?
Two possible values.
Which data type is best for a single letter such as a grade 'B'?
CHAR holds one character.
Which data type should be used for a telephone number?
No calculations are done with it, and a leading zero must be kept.
What is a constant?
Such as the number of days in a week.
What does DECLARE Score : INTEGER do?
It names the variable and gives its data type.
Quiz
6 questions
Tap an answer and you’ll see straight away whether it’s right, and why.
Worksheet
2 questions, 6 marks. Write your answers on paper, then check them.
Variables, constants and data types
Cambridge IGCSE Computer Science (9–1) 0984 · 6 marks · papermunch.org
Name ______________________________ Date ______________
Describe the difference between a variable and a constant.[2]
Show answerHide answer
The value of a variable can change while the program is running. The value of a constant cannot.
State the most suitable data type for each of these: the price of a book, the number of books in stock, the title of the book, whether the book is on loan.[4]
Show answerHide answer
Price: REAL. Number in stock: INTEGER. Title: STRING. On loan: BOOLEAN.
Answers: Variables, constants and data types
- 1. The value of a variable can change while the program is running. The value of a constant cannot.
- 2. Price: REAL. Number in stock: INTEGER. Title: STRING. On loan: BOOLEAN.



