Cambridge IGCSE Computer Science · 0478
Topic 8: Programming — Part 1
Data Types & Operators
Identifiers, variables, and constants
An identifier is a name given to a variable, constant, or subroutine. Identifiers must start with a letter and should be meaningful so other programmers can understand the code — for example, use TotalMarks rather than X. Meaningful identifiers improve maintainability.
A variable is a named storage location whose value can change while the program runs. Variables are declared with a data type:
DECLARE Score : INTEGER Score ← 75
A constant is a named value that must stay the same throughout the program. Constants help prevent accidental changes and allow you to update a fixed value once at the top of the code:
CONSTANT MaxAttempts ← 3 CONSTANT PassMark ← 50
Advantages of constants include: values cannot be changed accidentally during execution, and if a fixed value needs updating (such as a tax rate), you change it in one place only.
Data types
Every variable must be declared with a data type that defines what kind of value it can store:
| Data type | Description | Example |
|---|---|---|
| INTEGER | Whole numbers (positive, negative, or zero) | 42, -7, 0 |
| REAL | Numbers with a fractional part | 3.14, 98.6 |
| BOOLEAN | True or false values | TRUE, FALSE |
| CHAR | A single character | 'A', '7' |
| STRING | A sequence of zero or more characters | "Hello", "" |
Exam Traps
- CHAR holds one character in single quotes; STRING holds text in double quotes —
"A"is a string,'A'is a char.
Operators
Arithmetic operators
Arithmetic operators perform calculations on numeric values:
| Operator | Meaning | Example |
|---|---|---|
| + | Addition | 5 + 3 = 8 |
| - | Subtraction | 10 - 4 = 6 |
| * | Multiplication | 6 * 2 = 12 |
| / | Real division (may produce a decimal result) | 10 / 3 = 3.333… |
| ^ | Exponent (power) | 2 ^ 3 = 8 |
| DIV | Integer division (whole number quotient) | 10 DIV 3 = 3 |
| MOD | Remainder after integer division | 10 MOD 3 = 1 |
Relational operators
Relational operators compare two values and return a BOOLEAN result (TRUE or FALSE):
= equal to · <> not equal to · < less than · > greater than · <= less than or equal to · >= greater than or equal to
IF Score >= PassMark THEN
OUTPUT "Pass"
ENDIF
Logical operators
Logical operators combine BOOLEAN conditions:
- AND — both conditions must be true
- OR — at least one condition must be true
- NOT — reverses a condition (true becomes false, and vice versa)
IF Age >= 18 AND HasTicket = TRUE THEN
OUTPUT "Entry allowed"
ENDIF
Exam Traps
- DIV performs integer division (whole number quotient); / performs real division and may return a decimal — do not confuse them.
0/15