📘 Paper 3 · 3.1 Data Representation
3.1.1 User-Defined Data Types
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:

TYPE Season = (Spring, Summer, Autumn, Winter)
DECLARE currentSeason : Season
currentSeason ← Spring

// Comparison using ordinal position
IF currentSeason = Summer THEN
  OUTPUT "It's summer!"
ENDIF

// More examples of enumerated types:
TYPE Day = (Mon, Tue, Wed, Thu, Fri, Sat, Sun)
TYPE Suit = (Clubs, Diamonds, Hearts, Spades)
TYPE TrafficLight = (Red, Amber, Green)

Why use enumerated types?

  • 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:

TYPE Student
  DECLARE name : STRING
  DECLARE age : INTEGER
  DECLARE grade : CHAR
  DECLARE isPassed : BOOLEAN
ENDTYPE

Declaring and using record variables

DECLARE s1 : Student

// Assign values to individual fields using dot notation
s1.name ← "Alice"
s1.age ← 17
s1.grade ← 'A'
s1.isPassed ← TRUE

// Read individual fields
OUTPUT s1.name & " scored grade " & s1.grade

// 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

FeatureArrayRecord
Data typesAll elements same typeFields can be different types
AccessBy index: arr[i]By field name: rec.field
Use caseList of same-type valuesOne entity with multiple attributes
SizeFixed (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
TYPE IntPointer = ^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

TYPE NodePointer = ^Node

TYPE Node
  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:

TYPE IntSet = 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 3 IN 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]
✅ Mark scheme
TYPE IntPtr = ^INTEGER [1]; DECLARE p : IntPtr [1]; NEW(p) [1]; p^ ← 99 [1]; OUTPUT p^ [1]; DISPOSE(p) [1].
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!
TermDefinition
🎯

Mini Test — 3.1.1 User-Defined Data Types

10 questions · 10 marks · 10 minutes

← 2.5.3 Functional & Declarative
51 of 82 · Cambridge 9618
3.1.2 File Organisation →