🗂️ Paper 2 · 2.2 Data Types & Structures
2.2.1 Data Types
Cambridge 9618 · International A Level Computer Science · ~12 min read
Notes
Video
Slides
Quiz
Worksheet

The Five Core Data Types

Cambridge 9618 requires knowledge of five fundamental data types. Every variable must be declared with one of these types using the DECLARE keyword:

Integer

INTEGER

Whole numbers, positive or negative. No decimal point.
e.g., 0, -5, 42, 1000

Real

REAL

Numbers with a decimal point (floating-point).
e.g., 3.14, -0.5, 2.0, 9.81

Char

CHAR

A single character. Enclosed in single quotes.
e.g., 'A', '5', '!', ' '

String

STRING

A sequence of characters. Enclosed in double quotes.
e.g., "Hello", "9618", "", "AB12"

Boolean

BOOLEAN

Only two possible values: TRUE or FALSE.
Used for conditions and flags.

Declaring Variables in Cambridge 9618

DECLARE score : INTEGER
DECLARE temperature : REAL
DECLARE grade : CHAR
DECLARE name : STRING
DECLARE passed : BOOLEAN

// Assignment examples
score ← 85
temperature ← 36.6
grade ← 'A'
name ← "Alice"
passed ← TRUE

Constants

A constant is a named storage location whose value does not change during program execution. Cambridge 9618 uses the CONSTANT keyword:

CONSTANT PI = 3.14159
CONSTANT MAX_SIZE = 100
CONSTANT TAX_RATE = 0.20
CONSTANT GREETING = "Hello"

Note: constants use = not in their declaration. They cannot be changed later in the program.

Why use constants?

  • ReadabilityPI * radius * radius is clearer than 3.14159 * radius * radius
  • Maintainability — change the value in one place rather than throughout the entire program
  • Prevents accidental changes — compiler/interpreter will flag any attempt to change a constant

Type Casting (Type Conversion)

Cambridge 9618 provides built-in functions for converting between data types:

FunctionConvertsExampleResult
INT(x)REAL → INTEGER (truncates)INT(3.7)3
REAL(x)INTEGER → REALREAL(5)5.0
STRING(x)Any → STRINGSTRING(42)"42"
INT(x)STRING → INTEGERINT("25")25
REAL(x)STRING → REALREAL("3.14")3.14
CHR(n)INTEGER → CHAR (ASCII)CHR(65)'A'
ASC(c)CHAR → INTEGER (ASCII code)ASC('A')65

String Operations

Cambridge 9618 provides built-in string functions:

FunctionPurposeExampleResult
LENGTH(s)Number of charactersLENGTH("Hello")5
LEFT(s, n)First n charactersLEFT("Cambridge",4)"Camb"
RIGHT(s, n)Last n charactersRIGHT("Cambridge",5)"ridge"
MID(s, pos, n)n chars from posMID("Cambridge",2,3)"amb"
UCASE(s)Convert to uppercaseUCASE("hello")"HELLO"
LCASE(s)Convert to lowercaseLCASE("HELLO")"hello"

Choosing the Right Data Type

SituationCorrect typeReason
Counting items (e.g., number of students)INTEGERWhole numbers only; no fractions of a student
Price, temperature, weightREALFractional values needed
Grade (A, B, C...)CHARSingle character
Full name, addressSTRINGMultiple characters
Is logged in? / Has passed?BOOLEANOnly true/false needed
AgeINTEGERAge is always a whole number
Bank account balanceREALRequires pence/cents (decimal)
Exam tip: Cambridge mark schemes specifically check that DECLARE includes the correct type. Common errors: using REAL for counting (should be INTEGER); using STRING for a single character (should be CHAR); forgetting to declare variables at all. Also note — CHAR literals use single quotes ('A') but STRING literals use double quotes ("Alice").
⚠️ Common Mistakes
  • Declaring a counter as REAL — counters that always hold whole numbers should be INTEGER
  • Declaring a single letter grade as STRING — use CHAR for single characters
  • Using = for variable assignment — use (= is only for comparison and CONSTANT declarations)
  • Confusing INT(3.7) = 3 (truncates, not rounds) — INT truncates towards zero, doesn't round
  • Writing CHAR literals in double quotes — CHAR uses single quotes: 'A' not "A"
✅ Notes completed!
Video coming soon
Click slide or press arrow keys to navigate

Worksheet — 2.2.1 Data Types

8 questions · Cambridge 9618 standard

Q1State the five data types supported in Cambridge 9618 pseudocode and give one example value for each.[5]
✅ Mark scheme
INTEGER — e.g., 42 [1]; REAL — e.g., 3.14 [1]; CHAR — e.g., 'A' [1]; STRING — e.g., "Hello" [1]; BOOLEAN — TRUE or FALSE [1].
Q2For each variable below, state the most appropriate data type and explain your choice:
(a) The number of days in a month
(b) A student's surname
(c) The average mark of a class
(d) Whether a student is enrolled
[4]
✅ Mark scheme
(a) INTEGER — days in a month are always whole numbers [1]; (b) STRING — surnames contain multiple characters [1]; (c) REAL — average can be a non-integer e.g., 73.5 [1]; (d) BOOLEAN — only TRUE (enrolled) or FALSE (not enrolled) needed [1].
Q3What value does INT(7.9) return in Cambridge 9618? Explain why.[2]
✅ Mark scheme
INT(7.9) returns 7 [1]; because INT truncates (removes the decimal part) — it does NOT round. 7.9 → 7, not 8 [1].
Q4Write Cambridge 9618 pseudocode to declare a constant called SPEED_OF_LIGHT with the value 299792458 (an integer). Then declare an integer variable distance and assign it the value 1500000.[3]
✅ Mark scheme
CONSTANT SPEED_OF_LIGHT = 299792458 [1]; DECLARE distance : INTEGER [1]; distance ← 1500000 [1].
Q5What does MID("Cambridge", 4, 3) return? Show your working.[2]
✅ Mark scheme
MID("Cambridge", 4, 3) returns "bri" [1]; the function starts at position 4 (C=1,a=2,m=3,b=4) and takes 3 characters: b, r, i [1]. Note: Cambridge pseudocode uses 1-based indexing for string functions.
Q6State two advantages of using named constants instead of literal values (magic numbers) in a program.[2]
✅ Mark scheme
Any two: named constants improve readability — the programmer can understand what the value represents [1]; if the value needs to change, it only needs to be updated in one place [1]; prevents accidental modification of the value during program execution [1].
Q7Write pseudocode for a linear search algorithm as a FUNCTION LinearSearch(List : ARRAY[1:N] OF INTEGER, Target : INTEGER, N : INTEGER) RETURNS INTEGER. The function should return the index of Target if found, or -1 if not found. Use a FOR loop and an early exit mechanism.[5]
✅ Mark scheme
FUNCTION header with correct parameters and return type [1]; DECLARE or initialise a Found : BOOLEAN ← FALSE and index variable [1]; FOR loop from 1 to N [1]; IF List[i] = Target THEN RETURN i (or set Found ← TRUE, store index, break/exit loop) [1]; After loop: RETURN -1 if not found [1]. Accept equivalent correct pseudocode with early exit via RETURN inside loop or a flag.
Q8Compare linear search and binary search in terms of: (a) preconditions on the data, (b) time complexity (best and worst case), (c) suitability for small vs large datasets. Recommend which to use for a sorted list of 1,000,000 records, justifying your answer.[6]
✅ Mark scheme
(a) Linear: no precondition, works on unsorted data; Binary: list must be sorted beforehand [1]; (b) Linear: O(1) best (first element), O(n) worst; Binary: O(1) best (midpoint), O(log n) worst [1]; (c) Linear suits small datasets — low overhead, no sorting required; Binary suits large datasets — O(log n) dramatically fewer comparisons [1]; Recommendation: binary search for 1,000,000 sorted records [1]; justification: O(log₂(1,000,000)) ≈ 20 comparisons vs up to 1,000,000 for linear — an enormous efficiency gain [1]; Award 1 mark for any additional valid comparison point [1]. Award max 6.
Topic Quiz
Question 1 of 10
You scored
out of 10
Card 1 of 7
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — 2.2.1 Data Types

10 questions · 10 marks · 10 minutes

← 2.1.3 Abstraction
37 of 82 · Cambridge 9618
2.2.2 Arrays →