Arrays, Lists and Records
Storing lots of data together
A single variable holds one value. Data structures let you store many related values under one name. At GCSE you need arrays (and lists), and often records.
Arrays
An array is an ordered collection of items of the same data type, stored under one name and accessed by an index (position number).
- Most languages start indexing at 0, so the first item is index 0.
- Example:
scores = [10, 25, 8, 42] scores[0]= 10 (the first item)scores[3]= 42 (the fourth item)- You can read and change items by index:
scores[1] = 30.
Looping through an array
Because arrays are indexed, a FOR loop is perfect for processing every item:
total = 0
for i = 0 to 3
total = total + scores[i]
next i
This adds up all four scores.
2D arrays
A two-dimensional array is like a table or grid, accessed with two indexes (row, column): grid[2][1]. Useful for things like a seating plan, board game, or spreadsheet of data.
Lists
A list is similar to an array but is usually more flexible — it can grow and shrink, and (in some languages) hold mixed data types. Common operations: append (add to the end), remove, and insert.
Records
A record stores related data of different types together as fields — like one row of a database.
Example — a record for a student:
| Field | Type | Value |
|---|---|---|
| name | String | "Aisha" |
| age | Integer | 15 |
| average | Real | 78.5 |
| present | Boolean | True |
You access a field by name, e.g. student.age. An array of records can store many students.
Array vs record
| Array | Record | |
|---|---|---|
| Data types | All the same | Can be different |
| Accessed by | Index (number) | Field name |
| Good for | A list of similar items | One thing with several attributes |
Worked example
For colours = ["red", "green", "blue"], what is colours[1]?
- Indexing starts at 0, so index 1 is the second item = "green". ✓
Common mistakes
- Forgetting arrays are usually zero-indexed, causing off-by-one errors.
- Trying to store different data types in one array (use a record instead).
- Reading past the end of the array (e.g.
scores[4]when the last index is 3).
Exam tips
- State that arrays are fixed type, index-accessed; records are mixed type, field-accessed.
- Be ready to trace a loop that sums or searches an array.
- For 2D arrays, be clear which index is the row and which is the column.
Key facts to remember
- Array = ordered, same-type items accessed by index (usually from 0); 2D arrays use two indexes.
- List = like an array but flexible (can grow/shrink).
- Record = related fields of different types accessed by name; an array of records stores many.