Data types
Every variable in a program holds data of a particular type. The type tells the computer how to store the value, what operations are allowed, and how much memory it occupies. Choosing the right type avoids bugs and saves memory.
The five GCSE data types
| Type | Stores | Example values | Memory (typical) |
|---|---|---|---|
| Integer | Whole numbers | 0, -7, 42, 1000 | 4 bytes |
| Real | Decimal numbers | 3.14, -0.5, 100.0 | 4 or 8 bytes |
| Boolean | true / false | true, false | 1 byte |
| Character | Single character | 'A', '?', '7' | 1 byte (ASCII) |
| String | Sequence of chars | "hello", "AQA8525" | varies |
You may also see "Real" called float in many programming languages.
Why typing matters
- Operation correctness.
5 + 3(integers) gives 8."5" + "3"(strings) gives "53" (concatenation). The type changes the meaning of+. - Storage size. A boolean fits in 1 byte, a string of 100 characters needs 100 bytes (ASCII).
- Validity of comparison.
"10" < "2"returns true because of alphabetical order;10 < 2(integers) returns false. - Range. A 32-bit integer holds values from −2,147,483,648 to +2,147,483,647. Going outside causes overflow.
Integer vs real
Use integers when you're counting things — number of students, number of attempts, year of birth.
Use reals when you need fractional precision — temperatures, lengths, money (often, although a ££.pp is sometimes stored as integer pence to avoid floating-point error).
SET count TO 5 -- integer
SET temperature TO 22.5 -- real
Booleans
A boolean has just two values: true or false. They are the result of comparison operators and the inputs to the logical operators AND, OR, NOT.
SET isPassing TO score >= 50
IF isPassing AND attendance > 0.8 THEN
OUTPUT "On track"
ENDIF
Character vs string
A character is a single letter, digit or symbol — a single ASCII value. A string is a sequence of characters; even an empty string "" is valid.
SET initial TO 'J' -- character (single quotes)
SET name TO "Jonny" -- string (double quotes)
In AQA pseudocode, both kinds of literal are usually written with double quotes; the distinction is by context.
Choosing the right type — practical examples
- Age of a student → integer (we don't say 17.5).
- Height in metres → real (1.72).
- "Has the user logged in?" → boolean.
- A postcode → string (because it contains letters).
- A grade ('A', 'B', 'C') → character if a single letter; string if grade strings like "9", "8" or "U".
Type conversion
Sometimes you need to convert between types. Common operations:
STRING_TO_INT(s)— turn a string of digits into a number.INT_TO_STRING(n)— turn a number into its decimal string.STRING_TO_REAL(s),REAL_TO_STRING(r).
USERINPUT returns a string in many languages — students forget to convert before doing arithmetic. "3" + "4" is "34", not 7.
Common pitfalls
- Storing a phone number as integer (loses leading 0). Use string.
- Storing money as real — floating-point round-off. Use integer pence/cents.
- Comparing a string to an integer (
"5" = 5is false in most languages). - Forgetting to convert string input before arithmetic.
- Booleans assigned the string "true" instead of the value true.
➜Try this— Quick check
What is the most appropriate data type for each?
- number of pupils in a class → integer
- time of day on a 24-hour clock → string (or integer for minutes since midnight)
- whether a checkbox is ticked → boolean
- user's surname → string
- a single grade letter → character
Why this matters in exams
Examiners often ask "state the most appropriate data type and justify". The justification matters as much as the type — say why a string is needed for a postcode (contains letters and a space), or why integer is needed for a count (whole numbers only).
AI-generated · claude-opus-4-7 · v3-deep-computer-science