These types are built from a single primitive type but give the programmer a new name or a restricted set of values.
| Type | Purpose | Cambridge‑style pseudocode |
|---|---|---|
| Enumerated type | Variable may take one value from a fixed list. | ENUM Day { Mon, Tue, Wed, Thu, Fri, Sat, Sun } |
| Pointer type | Stores the address of a variable of a given type; enables dynamic structures such as linked lists. | TYPE PtrToInt IS POINTER TO INTEGER |
| Set type | Unordered collection of distinct values taken from a defined domain; useful for membership testing. | SET OF INTEGER S = { 1, 3, 5 } |
ENUM Colour { Red, Green, Blue };Colour favourite := Blue;
TYPE PtrToNode IS POINTER TO Node;RECORD Node {
data : INTEGER;
next : PtrToNode; // pointer to another Node
}
Why a pointer is needed: the size of a Node record is fixed, but the number of nodes required by a linked list is not known at compile‑time. By storing only the address of the next node, we can create an arbitrarily long chain of nodes without allocating a huge contiguous block of memory.
Memory‑layout illustration (simplified):
+-------------------+ +-------------------+
| Node p | ---> | Node q |
|-------------------| |-------------------|
| data = 12 | | data = 27 |
| next = address(q) | | next = NIL |
+-------------------+ +-------------------+
SET OF CHAR VOWELS = { 'a', 'e', 'i', 'o', 'u' };IF ch IN VOWELS THEN
OUTPUT "vowel"
ENDIF
Real‑world entities usually consist of several related pieces of data. Grouping those pieces into a single logical unit improves readability, maintainability and data integrity, and provides the building blocks for abstract data types.
A record is a collection of named fields, each of which may have a different primitive type.
RECORD Point {x : INTEGER;
y : INTEGER;
}
Access fields with the dot operator (.) or the arrow operator (->) when a pointer to a record is used.
An array stores a fixed number of elements of the same type, indexed from 1 (Cambridge convention).
DECLARE scores : ARRAY [1..10] OF INTEGER;DECLARE marks : ARRAY [1..5] OF INTEGER := {90, 85, 78, 92, 88};
A tuple is a fixed‑size, ordered collection that may contain elements of different types. In many languages tuples are immutable; in Cambridge pseudocode they are treated as a record without field names.
DECLARE person : TUPLE (STRING, INTEGER, BOOLEAN) := ("Alice", 23, TRUE);A class combines data (attributes) and behaviour (methods). Objects are instances of a class. The Cambridge syllabus expects the term “class” but also recognises that a simple record can be used when no methods are required.
CLASS Circle {PRIVATE radius : REAL;
PUBLIC CONSTRUCTOR(r : REAL) {
radius := r;
}
PUBLIC FUNCTION area() : REAL {
RETURN 3.14159 * radius * radius;
}
}
Creating a new name for an existing type can make code clearer.
TYPE Point2D IS RECORDx : INTEGER;
y : INTEGER;
END RECORD;
DECLARE p : Point := (0,0);).. (or -> for a pointer) to read or modify a field.RECORD Student {id : STRING;
name : STRING;
age : INTEGER;
GPA : REAL;
}
DECLARE class : ARRAY [1..5] OF Student;/* Initialise the first element */
class[1] := ("S001", "Emma", 19, 3.7);
/* Function to compute the average GPA of an array of students */
FUNCTION averageGPA(studs : ARRAY [1..n] OF Student; n : INTEGER) : REAL
DECLARE total : REAL := 0.0;
FOR i FROM 1 TO n DO
total := total + studs[i].GPA;
ENDFOR
RETURN total / n;
ENDFUNCTION
class[i].GPA is self‑explanatory.major : STRING) requires only one change to the record definition, not to every parallel array.calculateHonours()) were required; a record is sufficient for pure data storage.Composite types are the building blocks of ADTs. Choose the type that matches the required operations.
ARRAY with a top index, or a linked list of Node records.ARRAY or linked list of records with front and rear pointers.Node { data : INTEGER; next : PtrToNode; } demonstrates the combined use of a record and a pointer.left and right pointers; recursive algorithms traverse the composite structure.When designing an algorithm, consider:
ARRAYTUPLE or RECORDCLASSCLASS protects data integrity by restricting direct field access.Student record and a function that operates on an array of Student objects.
+---------------------------+ +---------------------------+
| Student record | | averageGPA(students) |
|---------------------------| |---------------------------|
| id : STRING | | total := 0 |
| name : STRING | | FOR each s in students |
| age : INTEGER | ---> | total := total + s.GPA |
| GPA : REAL | | ENDFOR |
+---------------------------+ | RETURN total / n |
+---------------------------+
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.