# Records

> Computer Science · CIE A-Level 9618
> Source: https://www.owlsprep.com/study/cie-9618-u10-records/

Records are core composite data types that group related values of different types to describe real-world entities. This module covers declaration, field access, arrays of records and CIE exam conventions.

**Prerequisites:** [Primitive data types](https://www.owlsprep.com/study/cie-9618-u10-primitive-data-types/); [1D arrays](https://www.owlsprep.com/study/cie-9618-u10-arrays/)

## Learning objectives

- Define a record as a composite data type
- Declare records and instances following CIE pseudocode conventions
- Access and modify record fields using dot notation
- Implement and process arrays of records

## 1. What is a Record?

**Record (Composite Data Type)** — A fixed collection of related data items (called fields) that can be of different data types, used to represent attributes of a single real-world or abstract entity.

*Example:* A `Student` record could have fields for name (string), age (integer), and enrolment status (boolean).

Unlike arrays, which store multiple values of the same type accessed by index, records group heterogeneous data where each field is identified by a unique name. This makes records ideal for modeling structured objects with multiple distinct attributes.

> **info**
>
> Records are called structs in C-like languages and are the foundation of objects in object-oriented programming. CIE exam pseudocode uses the standard `RECORD` keyword for all declarations.

**Worked example:** Identify which of the following is best represented as a single record: (A) A list of 100 test scores, (B) The details of a single customer order, (C) A table of 50 employee entries

1. Recall that a single record describes one entity with multiple attributes. Check each option:
2. Option A: All test scores are integers of the same type → best stored as an array, not a single record.
3. Option B: A customer order has multiple attributes of different types: order ID (integer), customer name (string), total cost (float) → matches the definition of a single record.
4. Option C: 50 employee entries → each employee is a record, so this is an array of records, not a single record.
5. Final answer: B

## 2. Declaring Records in CIE Pseudocode

**Record Declaration** — The process of defining a new record type's structure, including the name and data type of each field. Once declared, the record type can be used to create individual instances.

CIE exams follow a standard pseudocode format for declaring records, which you must use to get full marks. The general format is:

$$\begin{aligned} \text{DECLARE } &\langle\text{RecordName}\rangle \text{ RECORD} \\ &\langle\text{Field1}\rangle : \langle\text{DataType}\rangle \\ &\langle\text{Field2}\rangle : \langle\text{DataType}\rangle \\ &... \\ \text{END RECORD} \end{aligned}$$

**Worked example:** Declare a new record type called `Movie` with fields: title (string), release year (integer), rating (real), is_available (boolean). Then create an instance called `myMovie`.

1. Start the record declaration:
2. $$DECLARE Movie RECORD$$
3. Declare each field with its data type:
4. $$title : STRING \\ releaseYear : INTEGER \\ rating : REAL \\ isAvailable : BOOLEAN$$
5. Close the declaration and instantiate the record:
6. $$END RECORD \\ DECLARE myMovie : Movie$$

> **tip**
>
> Always include `END RECORD` to close your declaration. Omitting this will lose you an easy mark in CIE exams.

## 3. Accessing and Modifying Record Fields

Fields in a record are accessed using dot notation, which is standard across CIE pseudocode and most programming languages. The format is: $\textit{<record_instance>}.\textit{<field_name>}$. This notation works for both reading field values and assigning new values.

**Worked example:** Using the `Movie` record type from the previous section, assign values to `myMovie` and output the title and release year.

1. Assign values to each field using dot notation:
2. $$myMovie.title \leftarrow "Inception" \\ myMovie.releaseYear \leftarrow 2010 \\ myMovie.rating \leftarrow 8.8 \\ myMovie.isAvailable \leftarrow TRUE$$
3. Read the field values and output them:
4. $$OUTPUT myMovie.title + " (" + STRING(myMovie.releaseYear) + ")"$$
5. The final output will be: `Inception (2010)`

**Check your understanding**

Test your understanding of dot notation:

1. What is the correct way to output the rating of the `myMovie` instance?

   - OUTPUT Movie.rating
   - OUTPUT myMovie(rating)
   - OUTPUT myMovie.rating
   - OUTPUT rating.myMovie

   *Answer:* OUTPUT myMovie.rating

   *Why:* Correct! Dot notation follows the order `instance_name.field_name`, you cannot use the record type name to access a field.

## 4. Arrays of Records

The most common use of records in CIE exams is storing multiple entities of the same type as an array of records. This combines the benefits of arrays (simple iteration over elements) with records (storing heterogeneous attributes per entity). For example, you can store 100 movie entries as an array where each element is a `Movie` record.

**Worked example:** Declare an array of 20 `Movie` records called `cinemaCollection`, then output the title of every movie with a rating higher than 8.0.

1. Declare the array after defining the `Movie` record type:
2. $$DECLARE cinemaCollection : ARRAY[1:20] OF Movie$$
3. Loop through each element, check the rating field, and output matching titles:
4. $$FOR index \leftarrow 1 TO 20 \\ \quad IF cinemaCollection[index].rating > 8.0 THEN \\ \quad \quad OUTPUT cinemaCollection[index].title \\ \quad ENDIF \\ ENDFOR$$
5. This loop correctly checks each record in the array and outputs only titles that meet the condition.

> **info**
>
> You can also have nested records, where one record has a field that is another record type. Dot notation extends naturally: `myStudent.nextOfKin.phoneNumber` accesses the nested field correctly.

## Common pitfalls

- **Wrong:** Confusing record type with record instance when accessing fields.
  - Why it fails: The record type is just a template, only instances store actual data values.
  - Correct: Always use `instanceName.fieldName`, not `typeName.fieldName`.
- **Wrong:** Forgetting to close a record declaration with `END RECORD`.
  - Why it fails: CIE mark schemes require explicit closing of RECORD blocks to award full marks.
  - Correct: Always add `END RECORD` after declaring all fields of a record.
- **Wrong:** Incorrect dot notation order for fields in arrays of records.
  - Why it fails: Students often write `arrayName.fieldName[index]` instead of the correct order.
  - Correct: Index the array first, then access the field: `arrayName[index].fieldName`.
- **Wrong:** Using a single record to store multiple entities.
  - Why it fails: A record is designed to describe one entity. Storing multiple entities in one record makes iteration impossible.
  - Correct: Use an array of records: one record per entity, stored as elements in the array.

## Cheatsheet

| Concept | CIE Pseudocode Format |
| --- | --- |
| Declare record type | DECLARE &lt;Name&gt; RECORD<br>&lt;Field&gt;: &lt;Type&gt;<br>END RECORD |
| Declare record instance | DECLARE &lt;InstanceName&gt;: &lt;RecordName&gt; |
| Access record field | &lt;Instance&gt;.&lt;FieldName&gt; |
| Declare array of records | DECLARE &lt;ArrayName&gt;: ARRAY[&lt;low&gt;:&lt;high&gt;] OF &lt;RecordName&gt; |
| Access field in array of records | &lt;ArrayName&gt;[&lt;index&gt;].&lt;FieldName&gt; |

## What's next

Records are a foundational composite data type that you will use extensively in both Paper 1 problem solving and Paper 2 programming tasks for CIE A-Level Computer Science. Mastering record declaration and field access is critical for handling structured real-world data, and it builds the foundation for understanding more advanced data structures like linked lists, classes, and relational database entries. You will often encounter records paired with file handling, where you read and write records to text or binary files to store persistent data. Understanding how to iterate over arrays of records is also a common requirement for implementing sorting and searching algorithms, which are core exam topics.

- [Linked Lists](https://www.owlsprep.com/study/cie-9618-u10-linked-lists/)
- [Stacks](https://www.owlsprep.com/study/cie-9618-u10-stacks/)
- [Queues](https://www.owlsprep.com/study/cie-9618-u10-queues/)

---

From [OwlsPrep](https://www.owlsprep.com) — free study guides for A-Level, IB, AP and IGCSE, written against the official syllabus. Canonical page: https://www.owlsprep.com/study/cie-9618-u10-records/
