From input to a stored value
A variable names a storage location whose value may change. A named constant holds a value that the program is not intended to change. Choose a suitable data type and follow the declaration or assignment notation used in the question. Integer stores whole numbers, real can represent fractional values, Boolean stores true or false, character stores one character and string stores a sequence of characters.
Input obtains a value from outside the program, such as the keyboard. Assignment evaluates the right-hand expression and stores its result in the named variable. Output sends a result to the display. A displayed number is not automatically saved between runs.
Worked example: tickets
- Set the constant ticket price to 4.50 and obtain an integer quantity of 3.
- Calculate total = 3 × 4.50 = 13.50; total needs a real data type.
- Output 13.50. Changing only quantity to 4 leaves the constant price, stored total and display unchanged. Recalculate total to store 18.00, then execute output again to update the display.
Use the type that fits the meaning: a phone number may contain digits but is normally text because arithmetic on it is not meaningful.
Choose the type from what a value means
A data type describes the kind of value a program can work with and which operations make sense. An integer is a whole number, including zero and negative whole numbers. A real value can have a fractional part; it can also represent a whole-number value such as 4.0. Boolean means True or False, not the quoted text 'False'.
A character is one character, such as a letter, digit or punctuation mark. A string is a sequence of characters and can be empty or only one character long. When asked for the most specific type for exactly one letter, choose character. Digit characters in an identifier need not be numbers used for arithmetic: converting '0074' to integer 74 loses its original leading zeroes.
A variable has a name used to access its current value. A named constant gives a meaningful name to a value that must stay fixed during the run. A declaration introduces a name; an initial assignment supplies a value. Some languages require a separate typed declaration; others introduce a variable on assignment. Follow the notation printed in your exam question rather than inventing a declaration syntax. A name that has not yet been assigned a value is not automatically zero, False or an empty string.
| Value in a cinema system | Suitable type | Why |
|---|---|---|
| Number of available seats: 0 | Integer | A whole-number count; zero is a valid stored value |
| Price that may include pence: 6.50 | Real | Fractional values must be possible |
| Booking confirmed: False | Boolean | One of two logical states |
| Row label: B | Character | Exactly one letter is required |
| Booking identifier: 0074 | String | All four digit characters, including leading zeroes, matter |
Choose the calculation the question actually asks for
Addition increases a total, subtraction finds a difference and multiplication combines equal groups. Real division / keeps a fractional quotient. For the positive whole-number examples here, DIV counts complete groups and MOD counts the items left over. These are different requested results, not alternative ways to format the same answer.
Evaluate brackets first, then multiplication and division before addition and subtraction. Operators of the same precedence are evaluated from left to right in these examples. A final context decision may follow the calculation: if a remainder of passengers is non-zero, another vehicle is needed. If the remainder is zero, do not add an unnecessary vehicle. OCR's separate casting and powers section covers its additional exponentiation requirement.
| Expression | Result | Interpretation |
|---|---|---|
| 8 + 3 * 2 | 14 | Multiply 3 by 2 before adding 8 |
| (8 + 3) * 2 | 22 | Brackets change the order |
| 20 - 3 - 2 | 15 | Subtract left to right |
| 22 / 5 | 4.4 | Real quotient |
| 22 DIV 5 | 4 | Four complete groups of five |
| 22 MOD 5 | 2 | Two items left over |
| 20 MOD 5 | 0 | No items remain |
A comparison produces a Boolean, not an assignment
Relational operators compare two values: equal to, not equal to, less than, greater than, less than or equal to, and greater than or equal to. The result is True or False. The inclusive comparisons include equality: five is at most five, but five is not less than five. The table uses words so neither board's assignment symbol is mistaken for a comparison.
AND is True only if both conditions are True. OR is inclusive: it is True if either condition or both conditions are True. NOT reverses a Boolean. Work out the bracketed comparisons before combining them. AQA and OCR programming conditions require AND, OR and NOT here; the separate Boolean-logic topic handles any board-specific extra gates.
| With count 5 and ready False | Result | Reason |
|---|---|---|
| count is equal to 5 | True | The values match |
| count is not equal to 5 | False | The values match |
| count is less than 5 | False | Equality does not satisfy a strict comparison |
| count is greater than 5 | False | Five is not greater than itself |
| count is at most 5 | True | The upper limit includes equality |
| count is at least 5 | True | The lower limit includes equality |
| (count is at most 5) AND ready | False | True AND False |
| (count is equal to 5) OR ready | True | True OR False |
| NOT ready | True | NOT False |
Continue with your exam board
The course combines lesson videos, interactive activities, topic questions and original exam mocks. Sign in to use the learning tools and save your progress; your account’s course access applies.
Independent learning resources. Not endorsed by AQA or OCR. These public introductions complement the full course and the official specification.