GCSE Revision Aid: This resource is designed to support your revision and may contain errors. If you find a discrepancy with your class teaching, your teacher is correct โ€” please let us know at gcserevise@scott.scottrix.co.uk.

CS6: Data Types

Foundation Higher AQAEdexcelOCREduqasCCEA

Understanding the five main data types, type casting, and why choosing the right data type matters for memory and validation.

Fastmail

๐Ÿ“‹ The Five Data Types

Definition: A data type defines the kind of data a variable can hold. Choosing the correct data type ensures data is stored efficiently and prevents errors.
Data Type Description Examples Memory
Integer A whole number (no decimal point) 42, -7, 0, 1000 2 or 4 bytes
Real / Float A number with a decimal point 3.14, -0.5, 9.81 4 or 8 bytes
Boolean Can only be TRUE or FALSE TRUE, FALSE 1 byte
Character A single symbol (letter, digit, punctuation) 'A', '7', '?', 'z' 1 byte (ASCII)
String A sequence of characters (text) "Hello", "CS123", "" Variable (1 byte per char)

๐Ÿ”ข Integer

Integer stores whole numbers only - no decimal points. Use integer for counts, ages, positions, and any value that cannot logically be fractional.
Integer Examples
age ← 16
score ← 0
lives ← 3
temperature ← -5
Common mistake: Storing 3.14 as an integer would lose the decimal part, storing only 3. If a value needs decimal precision, use Real/Float instead.

๐Ÿ“ Real / Float

Real (or Float) stores numbers with a decimal point. Use real for measurements, prices, averages, and scientific calculations where precision matters.
Real Examples
pi ← 3.14159
price ← 9.99
average ← 67.5
gravity ← 9.81
Important:
Real division (/) always returns a decimal result.
7 / 2 = 3.5 (real division)
7 DIV 2 = 3 (integer division - truncates the decimal)

โœ… Boolean

Boolean can only hold one of two values: TRUE or FALSE. Use boolean for flags, conditions, and yes/no questions.
Boolean Examples
isLoggedIn ← FALSE
hasPassed ← TRUE
gameOver ← FALSE
isValid ← TRUE
Boolean in Conditions
IF hasPassed = TRUE THEN
    OUTPUT "Congratulations!"
ELSE
    OUTPUT "Try again"
ENDIF

This is equivalent to:

IF hasPassed THEN
    OUTPUT "Congratulations!"
ENDIF

๐Ÿ”ค Character

Character stores exactly one symbol - a single letter, digit, or special character. Characters are enclosed in single quotes.
Character Examples
grade ← 'A'
separator ← ','
digit ← '7'
symbol ← '&'
Distinction: A character '5' is NOT the same as the integer 5. The character '5' has the ASCII code 53, while the integer 5 has the value five. They are stored and processed differently.

๐Ÿ“ String

String stores a sequence of zero or more characters. Strings are enclosed in double quotes. An empty string "" contains no characters.
String Examples
name ← "Alice"
message ← "Hello, World!"
empty ← ""
serialNumber ← "CS-2024-001"
String Operations
greeting ← "Hello" & " " & "World"   // Concatenation
len ← LENGTH("Computer")              // len = 8
sub ← SUBSTRING("Computer", 0, 3)    // sub = "Com"
pos ← POSITION("Hello", "ll")        // pos = 2

๐Ÿ”„ Type Casting and Conversion

Type casting means converting a value from one data type to another. This is necessary when performing operations that require specific types, or when reading input that arrives as a string.
Conversion Function Example Result
String to Integer INT() INT("42") 42
String to Real FLOAT() FLOAT("3.14") 3.14
Integer to String STR() STR(42) "42"
Real to Integer INT() INT(3.99) 3 (truncates, does not round)
Integer to Real FLOAT() FLOAT(7) 7.0
Character to Code ASC() ASC('A') 65
Code to Character CHR() CHR(65) 'A'
Type Casting in Practice
INPUT userAge             // userAge is received as a string "16"
age ← INT(userAge)     // Convert to integer 16
age ← age + 1         // Now we can do arithmetic: age = 17
OUTPUT "Next year you will be " & STR(age)  // Convert back to string for output

๐Ÿ’พ Why Data Types Matter

1. Memory Efficiency

Choosing the right data type saves memory. A Boolean needs only 1 byte, while a string might need many bytes. Using a string to store "TRUE" instead of a Boolean wastes memory.

2. Validation

Data Types Prevent Errors

If age is declared as an integer, the program will reject "hello" as input because it cannot be stored as an integer. The data type acts as a first line of validation.

age ← INT(INPUT("Enter age: "))
// If user enters "hello", this will cause an error
// If user enters "16", age becomes the integer 16

3. Correct Operations

Operations Depend on Type
a ← 5 + 3       // Integer addition: a = 8
b ← "5" + "3"   // String concatenation: b = "53"
c ← 5 / 2       // Real division: c = 2.5
d ← 5 DIV 2     // Integer division: d = 2

The + operator does different things depending on the data type!

โš ๏ธ Common Mistakes

Mistake Why It's Wrong How to Fix It
Using string for numeric data Cannot perform arithmetic on strings Cast to integer or real first
Using integer for decimal values Loses the decimal part Use real/float instead
Confusing '5' and 5 Character vs integer - different operations Remember quotes mean character/string
Not casting input INPUT usually returns a string Use INT() or FLOAT() to convert
INT(3.9) expecting 4 INT() truncates, it does not round Use rounding functions if needed

โ“ Practice Questions

Q1: Name the five main data types and give an example value for each.

Q2: What is the difference between the integer 7 and the string "7"?

Q3: What is the result of INT("25") + INT("10")?

Q4: Why should you store a person's age as an integer rather than a string?

Q5: Write pseudo-code that asks the user for a number, converts it to a real, divides it by 2, and outputs the result.

โœ… Answers

  1. Integer: 42, Real/Float: 3.14, Boolean: TRUE, Character: 'A', String: "Hello".
  2. The integer 7 can be used in mathematical operations (7 + 3 = 10). The string "7" is text and would concatenate ("7" + "3" = "73"). They are stored and processed differently.
  3. INT("25") = 25, INT("10") = 10, so 25 + 10 = 35.
  4. Storing age as an integer allows arithmetic (e.g. checking if age >= 18), saves memory, and validates that the input is a whole number. A string age cannot be compared numerically.
  5. INPUT userInput
    num ← FLOAT(userInput)
    result ← num / 2
    OUTPUT result

๐ŸŽฏ Exam Tips

โš ๏ธ Common Errors

โœ— Thinking integer division and float division always give the same result โœ“ Integer division truncates the decimal part (7 รท 2 = 3), while float division preserves it (7 รท 2 = 3.5). Using the wrong type causes data loss.

โœ— Confusing character and string data types โœ“ A character is a single symbol (e.g. 'A'), stored in 1 byte. A string is a sequence of characters (e.g. 'Hello'), and its storage depends on length.

โœ— Believing Boolean can only be TRUE/FALSE text โœ“ In most languages, Boolean values are stored as 1 (TRUE) or 0 (FALSE) in memory; the keywords TRUE/FALSE are how they are represented in code.

โœ— Forgetting that real/float numbers cannot represent all decimals exactly โœ“ Floating-point numbers use binary representation and cannot store some decimal fractions exactly (e.g. 0.1), which can cause rounding errors in calculations.

โœ๏ธ Model Answer

Full-Mark Response

A program stores a student's name, their test score as a whole number, their height in metres, and whether they have passed. State the most appropriate data type for each value and explain your choice. [4 marks]

Name: STRING โ€” a name consists of multiple characters (e.g. 'Alice'), so a string is needed rather than a single character. Test score: INTEGER โ€” test scores are whole numbers (e.g. 85), so integer is appropriate as no decimal part is needed. Height: REAL/FLOAT โ€” height in metres requires decimal places (e.g. 1.65), so a real/float type is needed to store the fractional part. Passed: BOOLEAN โ€” the student has either passed or not passed, so only two values (TRUE/FALSE) are needed, making Boolean the most efficient choice.

๐Ÿ“Š AO Deep Dive

Assessment Objective Analysis

AO1 (Computational Thinking โ€” 40%): Demonstrate knowledge and understanding of the principles and concepts of computer science, including data types: integer, real, string, character and boolean for AQA 8525, OCR J277 & Edexcel 1CP2.

AO2 (Application โ€” 40%): Apply knowledge and understanding of computer science, including data types: integer, real, string, character and boolean to analyse problems in computational terms and to design, write and evaluate solutions.

AO3 (Evaluation โ€” 20%): Evaluate the effectiveness, correctness and efficiency of computational solutions, including data types: integer, real, string, character and boolean, and make reasoned judgements about trade-offs.

๐Ÿ“ Exam Technique

GCSE Computer Science Exam Tips:
When asked about data types, always state the type AND explain why it is the most appropriate. Consider: does it need decimal places? Is it text or a single character? Is it a true/false value? Is it a whole number? Remember that INTEGER is for whole numbers only, REAL/FLOAT for decimals, STRING for text, CHAR for single characters, and BOOLEAN for true/false. Casting between types (e.g. str() to int()) is a common exam topic.

๐Ÿ“ Exam Questions by Topic

๐ŸŽฌ Video Resources

Share this page

Ready to ace your GCSE Computer Science exams?

Get the best revision books and guides to boost your grades.