TopMyGrade

GCSE/Computer Science/AQA

CS2.1Data types: integer, real (float), Boolean, character, string; choosing an appropriate type for given data

Notes

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

TypeStoresExample valuesMemory (typical)
IntegerWhole numbers0, -7, 42, 10004 bytes
RealDecimal numbers3.14, -0.5, 100.04 or 8 bytes
Booleantrue / falsetrue, false1 byte
CharacterSingle character'A', '?', '7'1 byte (ASCII)
StringSequence 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

  1. Storing a phone number as integer (loses leading 0). Use string.
  2. Storing money as real — floating-point round-off. Use integer pence/cents.
  3. Comparing a string to an integer ("5" = 5 is false in most languages).
  4. Forgetting to convert string input before arithmetic.
  5. Booleans assigned the string "true" instead of the value true.

Try thisQuick 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

Practice questions

Try each before peeking at the worked solution.

  1. Question 15 marks

    Match data type

    State the most appropriate data type for each:
    (a) age of a person in years
    (b) price of an item in pounds and pence
    (c) whether the user pressed enter
    (d) UK phone number
    (e) initial of first name

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  2. Question 23 marks

    Why string for phone

    Justify why a UK phone number should be stored as a string and not an integer.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  3. Question 33 marks

    Operator overloading

    Predict the result of these operations:
    (a) 5 + 3 (integers)
    (b) "5" + "3" (strings)
    (c) "Year" + 11 (string + integer in a strict language)

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  4. Question 43 marks

    Boolean expression

    A pupil writes "SET isAdult TO age > 17". What is the data type of isAdult? Give an example value and explain.
    
    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  5. Question 53 marks

    Memory usage

    A program stores 100,000 boolean flags vs 100,000 strings of single characters. Which uses more memory and why?

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  6. Question 64 marks

    Type conversion

    A user enters "47" via USERINPUT. The program then runs SET total TO answer + 3. Why might this give "473" rather than 50? Suggest a fix.
    
    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

  7. Question 73 marks

    Integer overflow

    A 32-bit signed integer can hold values from –2,147,483,648 to +2,147,483,647. Explain what happens when a program tries to assign 2,147,483,648 to such an integer, using the term overflow.

    Ask AI about this

    AI-generated · claude-opus-4-7 · v3-deep-computer-science

Flashcards

CS2.1 — Data types

10-card SR deck for AQA GCSE Computer Science topic CS2.1

10 cards · spaced repetition (SM-2)