A variable is a named location in memory that stores a value that can change during program execution.
The AQA assignment operator is ← (left-arrow). The right-hand side is evaluated first, then stored in the variable on the left.
A constant is a named value that cannot change once set. Constants make code more readable and easier to maintain — if a value needs updating, you only change it in one place.
| Feature | Variable | Constant |
|---|---|---|
| Value can change? | Yes | No |
| Naming convention | camelCase or lowercase | UPPER_CASE |
| Example | score ← 0 | CONSTANT MAX ← 100 |
| Operator | Meaning | Example | Result |
|---|---|---|---|
| + | Addition | 5 + 3 | 8 |
| - | Subtraction | 10 - 4 | 6 |
| * | Multiplication | 3 * 4 | 12 |
| / | Division (real) | 7 / 2 | 3.5 |
| DIV | Integer division (floor) | 7 DIV 2 | 3 |
| MOD | Remainder (modulus) | 7 MOD 2 | 1 |
| ^ | Exponentiation (power) | 2 ^ 3 | 8 |
MOD is also useful for checking if a number is even (n MOD 2 = 0) or for cycling through array indices.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| == | Equal to | 5 == 5 | True |
| != | Not equal to | 5 != 3 | True |
| < | Less than | 3 < 7 | True |
| > | Greater than | 7 > 3 | True |
| <= | Less than or equal to | 5 <= 5 | True |
| >= | Greater than or equal to | 4 >= 6 | False |
8 questions · 21 marks · Mark schemes on submit
| Term | Definition |
|---|
Timed exam conditions.