A variable is a named storage location in memory whose value can change while the program runs. Variables are declared with a name and assigned a value using the assignment operator (= or ← in pseudocode).
Variable names should be meaningful (e.g. totalScore not x). They cannot start with a number or contain spaces.
A constant is a named value that is set once and does not change during the program. In OCR J277 pseudocode, constants are declared using const.
Why use constants? They make code easier to read and maintain. If the value needs changing (e.g. VAT rate changes from 20% to 19%), you only change it in one place. They also prevent accidental changes to values that should never change.
| Feature | Variable | Constant |
|---|---|---|
| Value can change? | Yes — can be updated anytime | No — set once at declaration |
| OCR pseudocode | score = 0 | const MAX = 10 |
| Examples | score, name, count, total | PI, MAX_SIZE, VAT_RATE |
| Use case | Storing values that change during execution | Fixed values used throughout program |
| Operator | Name | Description | Example |
|---|---|---|---|
| + | Addition | Adds two values | 5 + 3 = 8 |
| - | Subtraction | Subtracts right from left | 10 - 4 = 6 |
| * | Multiplication | Multiplies two values | 6 * 7 = 42 |
| / | Division | Divides left by right (can give decimal) | 7 / 2 = 3.5 |
| DIV | Integer division | Whole number result, discards remainder | 7 DIV 2 = 3 |
| MOD | Modulo | Returns the remainder after integer division | 7 MOD 2 = 1 |
| ^ | Exponentiation | Raises to the power of | 2 ^ 3 = 8 |
| Operator | Meaning | Example (result) |
|---|---|---|
| == | Equal to | 5 == 5 → True |
| != | Not equal to | 5 != 3 → True |
| < | Less than | 3 < 7 → True |
| > | Greater than | 9 > 4 → True |
| <= | Less than or equal to | 5 <= 5 → True |
| >= | Greater than or equal to | 6 >= 10 → False |
| Operator | Meaning | Example |
|---|---|---|
| AND | Both conditions must be true | age >= 16 AND hasID == True |
| OR | At least one condition must be true | score > 50 OR bonus == True |
| NOT | Inverts the Boolean value | NOT locked → True if locked is False |
The + operator is used for string concatenation in OCR pseudocode — joining two strings together.
8 questions · 20 marks
| Term | Definition |
|---|
10 questions · 10 marks · 10 minutes