Data types
A data type tells the computer what kind of data a variable holds. This decides how much memory it needs, how it is stored in binary, and what you can do with it (you can multiply numbers, but not names).
| Data type | Holds | Example |
|---|---|---|
| Boolean | Only TRUE or FALSE, used for conditions | valid = True |
| Character | A single letter, digit or symbol | letter = 'A' |
| Integer | Whole numbers, positive or negative | age = 15 |
| Real | Numbers with a decimal point (also called float) | temperature = 36.4 |
| String | A sequence of characters: letters, digits, symbols, spaces | email = 'computer.science@wjec.co.uk' |
Choosing the right type
| Data | Best type | Why |
|---|---|---|
| Number of students in a class | Integer | Always whole |
| Price of an item, £3.99 | Real | Has a decimal part |
| Whether a member has paid | Boolean | Only yes or no |
| A grade, e.g. 'B' | Character | One character |
| A phone number, 07700 900123 | String | Not used in calculations, it may start with 0 (an integer would lose it), and it can contain spaces or a + |
| A postcode, SA10 6YY | String | Mix of letters, digits and a space |
In WJEC pseudo-code a variable's type is given like this: myvariable is integer.