SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 2 · Topic 2.2.1

Data Types &
User-Defined Types

Primitive Types · Type Casting · Enumerated · Pointer · Composite Types

CSZone Cambridge International AS & A Level Computer Science 9618
Primitive Data Types

The Building Blocks

TypeCAIE KeywordDescriptionExample
IntegerINTEGERWhole numbers, positive or negative42, -7, 0
RealREALNumbers with decimal point (floating-point)3.14, -0.5
BooleanBOOLEANOnly two values: TRUE or FALSETRUE, FALSE
CharacterCHARSingle character (letter, digit, symbol)'A', '5', '!'
StringSTRINGSequence of zero or more characters"Hello World"
DateDATERepresents a calendar date31/07/2026
User-Defined Types

Enumerated & Pointer Types

ENUMERATED TYPE
A named type with a finite set of possible values. Improves code readability. Defined with TYPE keyword.
TYPE Season = (Spring, Summer, Autumn, Winter)
DECLARE current : Season
current <- Summer
POINTER TYPE
Stores a memory address. Used to implement dynamic data structures (linked lists, trees). Declared with ^ prefix.
TYPE NodePtr = ^Node
TYPE Node
data : INTEGER
next : NodePtr
ENDTYPE
Pointer operations: ^ptr dereferences (accesses the value at the address). NEW(ptr) allocates memory. DISPOSE(ptr) frees memory.
Type Casting & Conversion

Converting Between Types

INT(x) — converts x to integer (truncates decimal). e.g. INT(3.9) = 3
REAL(x) — converts x to real. e.g. REAL(5) = 5.0
STR(x) — converts x to string. e.g. STR(42) = "42"
NUM_TO_STR(x) — numeric to string. Used for concatenation.
STRING_TO_NUM(s) — string to number. Used when reading numeric input.
CHR(n) — ASCII code to character. e.g. CHR(65) = 'A'
ASC(c) — character to ASCII code. e.g. ASC('A') = 65
String Operations

Built-in String Functions

s <- "Hello World"
OUTPUT LENGTH(s) // 11
OUTPUT LCASE(s) // "hello world"
OUTPUT UCASE(s) // "HELLO WORLD"
OUTPUT MID(s, 1, 5) // "Hello" (start, length)
OUTPUT LEFT(s, 5) // "Hello"
OUTPUT RIGHT(s, 5) // "World"
OUTPUT s[1] // 'H' (1-indexed in CAIE)
Exam Practice

Cambridge-style questions

Question 1
A programmer needs to store a day of the week in a variable. Suggest an appropriate user-defined type and write pseudocode to declare it.
3 marks
1 mark
Enumerated type — most appropriate as there are a fixed, finite number of valid values
TYPE Day = (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday) // 1 mark
DECLARE today : Day // 1 mark
Common Mistakes

Don't lose easy marks

1
Confusing CHAR and STRING — CHAR stores exactly one character; STRING stores zero or more. '5' is a CHAR (single-quoted). "5" is a STRING (double-quoted). Using the wrong type loses type-checking benefits.
2
Using INTEGER when the problem requires REAL — storing 3.9 in an INTEGER gives 3 (truncation). If a value can ever have a decimal part (prices, averages, measurements) use REAL.
3
MID function indexing — in CAIE pseudocode, MID(s, 1, 5) returns 5 characters starting from position 1 (1-indexed, not 0). Examiners expect the CAIE pseudocode convention, not Python/Java conventions.
Topic Summary — 2.2.1

What You Need to Know

PRIMITIVE TYPES
INTEGER · REAL · BOOLEAN
CHAR · STRING · DATE
DECLARE name : TYPE
USER-DEFINED TYPES
Enumerated: TYPE Name = (val1, val2...)
Pointer: TYPE NodePtr = ^Node
Records: TYPE...ENDTYPE
CONVERSION & STRING OPS
INT(), REAL(), STR()
CHR(n) / ASC(c)
LENGTH, MID, LEFT, RIGHT
LCASE, UCASE · 1-indexed in CAIE
CSZone

Next Video

2.2.2
Arrays
1D Arrays · 2D Arrays · Array Operations in Pseudocode
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools