🔒
Unlock Everything
£7.99/month
or £59/year
Subscribe now →
💻 Component 2 · 2.2 Programming
2.2.1b Data Types
OCR J277 · GCSE Computer Science · ~10 min read
Notes
Video
Slides
Worksheet
Quiz

Why Data Types Matter

Every piece of data stored in a program has a data type — it tells the computer how to store it in memory and what operations can be performed on it. Using the wrong data type causes errors: you can't multiply a string, and you can't store a decimal in an integer without truncation.

The OCR J277 Data Types

Integer
Whole numbers (positive, negative, or zero). No decimal point.
Examples: 0, 42, -7, 1000
Real / Float
Numbers with a decimal point. Also called 'real' in OCR J277.
Examples: 3.14, -0.5, 9.81, 1.0
Boolean
Can only store True or False. Used in conditions and flags.
Examples: True, False
Character (Char)
A single character enclosed in single quotes.
Examples: 'A', '5', '!', ' '
String
A sequence of zero or more characters. Enclosed in double quotes.
Examples: "hello", "Alice", "123"

Data Types — Comparison Table

Data typeWhat it storesMemoryOCR example
IntegerWhole numbers, no decimalTypically 4 bytesage = 16
Real/FloatNumbers with decimal pointTypically 8 bytesprice = 9.99
BooleanTrue or False only1 bit (1 byte typical)passed = True
CharacterSingle character1–4 bytes (Unicode)grade = 'A'
StringSequence of charactersVariablename = "Bob"

Type Casting — Converting Between Types

Sometimes you need to convert between data types. OCR J277 pseudocode uses these casting functions:

FunctionConverts toExampleResult
int(x)Integerint("42")42
float(x)Real/floatfloat("3.14")3.14
str(x)Stringstr(100)"100"
bool(x)Booleanbool(1)True
ord(c)ASCII code (integer)ord('A')65
chr(n)Characterchr(65)'A'

Common Use Cases

// Getting input and converting
userInput = input("Enter your age: ")  // input() always returns a string
age = int(userInput)                  // convert to integer for arithmetic

// Building a message with concatenation
score = 95
OUTPUT "Your score is: " + str(score) // must convert int to string

// Boolean use case
gameOver = False
IF lives == 0 THEN
    gameOver = True
END IF

String vs Integer — "123" vs 123

The value "123" (string) is NOT the same as 123 (integer). The string is stored as three characters. You cannot do arithmetic on it. If a user types a number into an input() box, it arrives as a string — you must use int() to convert it before arithmetic.

Exam tip: A very common exam question is "State the most appropriate data type for..." followed by a scenario. Key rules: age, score, quantity = integer. Price, weight, percentage = real/float. Yes/no, on/off, pass/fail = Boolean. Single letter/symbol = character. Name, address, message = string. Also know that input() always returns a string in most languages — you must cast it.
⚠️ Common Mistakes
  • Saying "123" (string) is the same data type as 123 (integer) — they are NOT
  • Using a real/float for something that should be an integer (e.g. number of students)
  • Confusing character (single char) and string (multiple chars) — 'A' vs "A"
  • Forgetting to convert input() from string before doing arithmetic
  • Saying Boolean stores 0 and 1 — it stores True and False (even if implemented as 0/1)
✅ Notes completed!
Video coming soon
Click slide or press arrow keys to navigate

Worksheet — 2.2.1b Data Types

8 questions · 20 marks

Q1State the five data types you need to know for OCR J277 and give one example value for each.[5]
✅ Mark scheme
One mark each for name + valid example: Integer (42) [1]; Real/float (3.14) [1]; Boolean (True/False) [1]; Character ('A') [1]; String ("hello") [1].
Q2State the most appropriate data type for each: (a) A student's name (b) A test score out of 100 (c) Whether a door is locked (d) The price of an item (e) A single grade letter[5]
✅ Mark scheme
(a) String [1]. (b) Integer [1]. (c) Boolean [1]. (d) Real/float [1]. (e) Character [1].
Q3A program asks the user to input their age. The input() function returns a string. Write the pseudocode to get and convert this input correctly.[2]
✅ Mark scheme
userInput = input("Enter your age: ") [1]; age = int(userInput) [1] (or in one line: age = int(input("Enter your age: ")))
Q4Explain why the statement OUTPUT "Score: " + score causes an error if score is an integer.[2]
✅ Mark scheme
You cannot concatenate (join) a string and an integer using + [1]. The integer must first be converted to a string using str(score) before concatenating: "Score: " + str(score) [1].
Q5What is the difference between the integer 42 and the string "42"?[2]
✅ Mark scheme
The integer 42 is stored as a numeric value and arithmetic can be performed on it (e.g. 42 + 8 = 50) [1]. The string "42" is stored as two characters ('4' and '2') and arithmetic cannot be performed on it — "42" + "8" = "428" (concatenation) [1].
Q6What does ord('Z') return and what does this tell us?[2]
✅ Mark scheme
ord('Z') returns 90 [1]. This is the ASCII code (integer value) for the character 'Z' — each character has a unique numeric code. chr(90) would return 'Z' [1].
Q7Why would you use a Boolean rather than a string to store whether a user has logged in?[1]
✅ Mark scheme
A Boolean (True/False) uses less memory than a string and is more efficient for a two-state condition [1]. It can be directly used in IF conditions without string comparison. Also avoids typos (e.g. "Ture").
Q8A program stores the number of goals scored in a football match. Should it use integer or real? Justify your answer.[1]
✅ Mark scheme
Integer [1] — you cannot score half a goal; goals are whole numbers. Using a real/float would waste memory and allow impossible values like 1.5.
?
out of 20 — self-mark above
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 9
Click to reveal definition
🎉
Complete!
TermDefinition
🎯

Mini Test — 2.2.1b Data Types

10 questions · 10 marks · 10 minutes

← 2.2.1a Variables & Operators 2.2 Programming 2.2.1c Sequence, Selection, Iteration →