Cambridge 9618 · International A Level Computer Science · ~18 min read
Notes
Video
Slides
Quiz
Worksheet
📘 Paper 3 — A Level Advanced Theory
What Are User-Defined Data Types?
Cambridge 9618 requires knowledge of four types of user-defined data types that programmers can create beyond the built-in types (INTEGER, REAL, CHAR, STRING, BOOLEAN):
🏷️
Enumerated Type
A named set of ordered constants. Useful when a variable should only be one of a limited list of values — e.g. days of the week, card suits, traffic light states.
📋
Record (Composite) Type
Groups together multiple fields of different types under one name. Similar to a row in a database table. Fields are accessed using dot notation.
➡️
Pointer Type
Stores the memory address of another variable or data structure. Used to create dynamic data structures (linked lists, trees) that grow/shrink at runtime on the heap.
🔢
Set Type
An unordered collection of unique values of the same type. Supports set operations: union, intersection, difference. Values cannot repeat.
1. Enumerated Type
An enumerated type defines a named list of allowed constant values. The values have an implicit order (position 0, 1, 2...) which allows comparison. In Cambridge 9618 pseudocode, the syntax is:
TYPESeason = (Spring, Summer, Autumn, Winter) DECLARE currentSeason : Season
currentSeason ← Spring
// Comparison using ordinal position IF currentSeason = Summer THEN
OUTPUT "It's summer!" ENDIF
Prevents invalid values — a variable of type Season can only hold Spring, Summer, Autumn or Winter; not arbitrary strings
Makes code more readable — IF signal = Red is clearer than IF signal = 1
Allows comparison and iteration — values have an implicit numeric order
2. Record Type
A record type (also called composite type) groups multiple fields of different data types into a single named unit. Each field has its own name and type. In Cambridge 9618 pseudocode:
TYPEStudent DECLARE name : STRING DECLARE age : INTEGER DECLARE grade : CHAR DECLARE isPassed : BOOLEAN ENDTYPE
// Arrays of records — e.g. a class of 30 students DECLARE class : ARRAY[1:30] OF Student
class[1].name ← "Bob"
class[1].grade ← 'B'
Record: s1 (type Student)
name
"Alice"
STRING
age
17
INTEGER
grade
'A'
CHAR
Records vs Arrays
Feature
Array
Record
Data types
All elements same type
Fields can be different types
Access
By index: arr[i]
By field name: rec.field
Use case
List of same-type values
One entity with multiple attributes
Size
Fixed (declared)
Fixed (number of fields)
3. Pointer Type
A pointer stores a memory address — it "points to" where a value is stored in memory, rather than storing the value itself. Pointers are essential for building dynamic data structures on the heap (memory allocated at runtime, not compile time).
In Cambridge 9618 pseudocode, a pointer type is declared with a caret symbol ^ before the target type:
// Declare a pointer type to INTEGER TYPEIntPointer = ^INTEGER
DECLARE p : IntPointer// p holds a memory address
NEW(p) // allocates memory on the heap; p now points to it
p^ ← 42// dereference p (p^) to store value 42 at that address
OUTPUT p^ // dereference to read: outputs 42
DISPOSE(p) // frees the allocated heap memory (prevents memory leak)
Variable: p (stack)
0xFF4A12
→
Heap memory at 0xFF4A12
42
Pointer in a linked list node
TYPENodePointer = ^Node
TYPENode DECLARE data : INTEGER DECLARE next : NodePointer// points to next node ENDTYPE
4. Set Type
A set is an unordered collection of unique values all of the same type. Sets support mathematical set operations. In Cambridge 9618:
TYPEIntSet = SET OF INTEGER
DECLARE A : IntSet DECLARE B : IntSet
A ← {1, 2, 3, 4}
B ← {3, 4, 5, 6}
// Set operations:
OUTPUT A UNION B // {1,2,3,4,5,6} — all unique elements
OUTPUT A INTERSECTION B // {3,4} — elements in both
OUTPUT A DIFFERENCE B // {1,2} — in A but not B
OUTPUT 3IN A // TRUE — membership test
Cambridge 9618 exam tip: Know the exact pseudocode syntax for each type — TYPE...ENDTYPE for records; TYPE name = (...) for enumerated; TYPE name = ^BaseType for pointers; TYPE name = SET OF BaseType for sets. For records, practise writing arrays of records (ARRAY[1:n] OF RecordType) and accessing fields (array[i].fieldName). Pointer NEW/DISPOSE and dereference (p^) are commonly tested.
⚠️ Common Mistakes
Forgetting ENDTYPE after a record type definition — every TYPE...ENDTYPE block must close
Using array access (arr[i]) for record fields instead of dot notation (rec.fieldName)
Forgetting to call NEW(p) before dereferencing a pointer — p^ is undefined until memory is allocated
Forgetting DISPOSE(p) after use — this causes memory leaks (heap memory not freed)
Thinking sets are ordered — sets have no defined order; elements are unique and unordered
Putting duplicate values in a set — sets only keep unique values (duplicates are ignored)
✅ Notes completed!
▶
Video coming soon
Click slide or press arrow keys to navigate
Worksheet — 3.1.1 User-Defined Data Types
8 questions · Cambridge 9618 standard
Q1Define an enumerated type TrafficLight with values Red, Amber, Green. Then declare a variable signal of this type and set it to Red.[3]
✅ Mark scheme
TYPE TrafficLight = (Red, Amber, Green) [1]; DECLARE signal : TrafficLight [1]; signal ← Red [1].
Q2Define a record type Car with fields: regNumber (STRING), make (STRING), year (INTEGER), mileage (REAL). Then declare a variable myCar of this type and assign appropriate values to each field.[6]
✅ Mark scheme
TYPE Car [1]; DECLARE regNumber : STRING; DECLARE make : STRING; DECLARE year : INTEGER; DECLARE mileage : REAL [1 per field, max 2]; ENDTYPE [1]; DECLARE myCar : Car [1]; myCar.regNumber ← "AB12 CDE" (or similar); myCar.year ← 2020; myCar.mileage ← 50000.0 [1 per assignment, max 2].
Q3Explain why a programmer would use a record type rather than separate variables for storing student data (name, age, grade).[2]
✅ Mark scheme
A record groups related data of different types together under one name, making the code more organised and readable [1]; it allows arrays of records to be declared — e.g. ARRAY[1:30] OF Student — so all student data can be accessed with one variable rather than multiple separate arrays [1].
Q4Write pseudocode to: (a) declare a pointer type IntPtr that points to INTEGER, (b) declare variable p of type IntPtr, (c) allocate memory, (d) store value 99 at the pointed location, (e) output the value, (f) free the memory.[6]
Q5Given sets A = {2, 4, 6, 8} and B = {4, 8, 12, 16}, state the result of: (a) A UNION B, (b) A INTERSECTION B, (c) A DIFFERENCE B.[3]
✅ Mark scheme
(a) A UNION B = {2, 4, 6, 8, 12, 16} — all unique elements from both sets [1]; (b) A INTERSECTION B = {4, 8} — elements in both A and B [1]; (c) A DIFFERENCE B = {2, 6} — elements in A that are not in B [1].
Q6Declare an array of 50 records of type Car (from Q2) and show how to assign the make of the 5th car to "Ford" and output the year of the 10th car.[3]
✅ Mark scheme
DECLARE fleet : ARRAY[1:50] OF Car [1]; fleet[5].make ← "Ford" [1]; OUTPUT fleet[10].year [1].
Q7Define a RECORD type in CAIE pseudocode for a student with fields: StudentID (INTEGER), Name (STRING), DateOfBirth (DATE), and IsEnrolled (BOOLEAN). Then write pseudocode to declare a variable MyStudent of this type and assign values to each field.[5]
✅ Mark scheme
TYPE Student / RECORD keyword used [1]; StudentID : INTEGER [1]; Name : STRING [1]; DateOfBirth : DATE [1]; IsEnrolled : BOOLEAN / ENDRECORD or ENDTYPE [1]; Declaration: DECLARE MyStudent : Student [1 bonus]; Field assignment e.g. MyStudent.StudentID ← 1001 [1 bonus]. Award max 5.
Q8State the difference between an enumerated type and a set type in CAIE pseudocode. Give one example of each using appropriate values, and explain one advantage of using an enumerated type over using integer constants to represent a fixed set of values.[4]
✅ Mark scheme
Enumerated type: a user-defined type listing named constants in a fixed ordered sequence e.g. TYPE Season = (Spring, Summer, Autumn, Winter) [1]; Set type: a collection of values of the same base type where membership can be tested e.g. TYPE DigitSet = SET OF INTEGER [1]; Advantage: enumerated type values have meaningful names making code more readable and self-documenting [1]; integer constants require the programmer to remember which integer maps to which concept, increasing the risk of errors; enumerated types also allow the compiler to check that only valid values are assigned [1].
Topic Quiz
Question 1 of 10
You scored
out of 10
Card 1 of 8
Click to reveal definition
🎉
All cards reviewed!
Term
Definition
🎯
Mini Test — 3.1.1 User-Defined Data Types
10 questions · 10 marks · 10 minutes
⏱ 10:00
Section A — Multiple Choice [5 marks]
Q1Which Cambridge 9618 pseudocode syntax correctly defines an enumerated type Colour with values Red, Blue, Green?
Q2To access the 'name' field of a record variable s1, which notation is used in Cambridge 9618 pseudocode?
Q3Which statement allocates heap memory for a pointer variable p in Cambridge 9618 pseudocode?
Q4What is the result of {1, 3, 5} INTERSECTION {3, 5, 7}?
Q5When should DISPOSE(p) be called for a pointer p?
Section B — Short Answer [5 marks]
Q6State two differences between an array and a record type.
Mark schemeAn array can only hold elements of the same data type; a record can hold fields of different data types [1]; array elements are accessed by index (arr[i]); record fields are accessed by field name using dot notation (rec.field) [1].
Q7Why are enumerated types useful? Give an example in Cambridge 9618 pseudocode.
Mark schemeEnumerated types restrict a variable to a specific set of named values, preventing invalid assignments and improving code readability [1]; example: TYPE Direction = (North, South, East, West); DECLARE facing : Direction; facing ← North — the variable can only ever hold one of the four direction values [1].
Q8What is the purpose of a pointer variable? Why are pointers needed for dynamic data structures?
Mark schemeA pointer stores a memory address (the location of a value) rather than the value itself [1]; dynamic data structures like linked lists and trees need to be created and resized at runtime — the pointer variable refers to heap memory allocated with NEW(), which can be created and freed as needed without knowing the size in advance at compile time [1].
Q9Write pseudocode to define a record type Book with fields title (STRING), author (STRING), pages (INTEGER). Declare an array of 100 Books and output the title of the 50th book.
Mark schemeTYPE Book [1]; DECLARE title : STRING; DECLARE author : STRING; DECLARE pages : INTEGER; ENDTYPE [1]; DECLARE library : ARRAY[1:100] OF Book [1]; OUTPUT library[50].title [1].
Q10Explain what happens if a programmer forgets to call DISPOSE(p) after using a pointer. What is this problem called?
Mark schemeIf DISPOSE(p) is not called, the heap memory allocated by NEW(p) is never freed [1]; this is called a memory leak [1]; over time, if many allocations are made without freeing memory, the available heap memory is exhausted, which can cause the program to crash or slow down [1].