A record groups together several related data items of possibly different data types, describing a single thing.
An array cannot do this — every element of an array must be the same type. A record can hold a String, a Real and an Integer side by side.
AQA's own example, from the specification
RECORD Car
make : String
model : String
reg : String
price : Real
noOfDoors : Integer
ENDRECORD
Each named item is a field. Notice the mixture: three Strings, a Real and an Integer, all describing one car.
Using a record
myCar.make ← 'Toyota'
myCar.model ← 'Yaris'
myCar.reg ← 'AB21 CDE'
myCar.price ← 12495.00
myCar.noOfDoors ← 5
OUTPUT myCar.make, ' ', myCar.model, ' — £', myCar.price
Fields are accessed by name using a dot: myCar.price. Compare this with an array, where you access by number: prices[3].
Why field names are better here. myCar.price says what it is. In an array you would have to remember that "index 3 is the price", which is fragile and unreadable.
Array vs record — choosing correctly
| Situation | Use | Why |
|---|
| 30 exam marks | Array | All the same type; you want to loop over them |
| One student's name, age and average | Record | Different types; they describe one person |
| Temperatures for each day of a week | Array | Same type, a list |
| One book's title, author, ISBN and price | Record | Different types, one book |
| 100 books, each with those four fields | Array of records | Both — see below |
Array of records — the powerful combination
RECORD Student
name : String
age : Integer
average : Real
ENDRECORD
students : ARRAY[0:29] OF Student # 30 Student records
students[0].name ← 'Amina'
students[0].age ← 15
students[0].average ← 78.5
# Now you can loop over all 30
FOR i ← 0 TO 29
OUTPUT students[i].name, ' scored ', students[i].average
ENDFOR
This is how a table of data is stored, and it is exactly the structure behind a database table (3.7.1): the array is the table, each record is a row, and each field is a column.
AQA tip. In an exam, write a record definition using the specification's own layout — RECORD name, one field : Type per line, then ENDRECORD. Mark schemes credit the field names and the correct data type for each, so choose types carefully (a price is Real, a count is Integer, a reg is String).