Cambridge IGCSE Computer Science (0478) · lesson 29 of 35 · 20 min
Variables and Constants
A variable is a named memory location whose value can change during program execution. A constant is a named value that is set once and cannot be changed — using constants makes code more readable and easier to maintain.
Data Types
Why Data Types Matter
Choosing the correct data type ensures:
- Correct operations (you cannot multiply two strings).
- Efficient memory use (BOOLEAN needs 1 bit; storing it as STRING wastes space).
- Avoiding errors (storing “abc” in an INTEGER variable causes a type error).
Type casting: Converting between types — e.g. converting the string “42” to the integer 42 before arithmetic.
Which data type would you use to store a student’s exam score (0–100)?
- BOOLEAN
- CHAR
- INTEGER
- STRING
Answer: INTEGER
Exam scores are whole numbers — INTEGER is the correct type.
What is the key difference between a variable and a constant?
- Constants are faster
- Variables can change value; constants cannot
- Constants use more memory
- Variables must be integers
Answer: Variables can change value; constants cannot
A variable’s value can change during execution; a constant’s value is fixed.
Which data type stores TRUE or FALSE?
- INTEGER
- STRING
- REAL
- BOOLEAN
Answer: BOOLEAN
BOOLEAN stores only two values: TRUE or FALSE.
Previous lesson: Bubble sort and merge sort
Back to Cambridge IGCSE Computer Science (0478)
Next lesson: Sequence, selection, and iteration