1D Arrays
An array is a data structure that stores multiple values of the same data type under a single variable name. Each value is accessed using an index (position number). In Edexcel 4CP0, arrays are indexed from 0.
# Declare a 1D array of 5 integers (indices 0 to 4)
SET scores[5] TO [85, 72, 91, 68, 79]
# Access individual elements
SEND scores[0] TO DISPLAY # outputs 85
SEND scores[2] TO DISPLAY # outputs 91
# Update an element
SET scores[1] TO 75 # changes 72 to 75
Iterating through a 1D Array
FOR i FROM 0 TO 4 DO
SEND scores[i] TO DISPLAY
END FOR
2D Arrays
A 2D array is an array of arrays — think of it as a table with rows and columns. Each element is accessed using two indices: [row][column].
# 3×3 grid (3 rows, 3 columns)
SET grid[3][3] TO [[1,2,3],[4,5,6],[7,8,9]]
# Access element at row 1, column 2
SEND grid[1][2] TO DISPLAY # outputs 6
# Nested loop to print all values
FOR row FROM 0 TO 2 DO
FOR col FROM 0 TO 2 DO
SEND grid[row][col] TO DISPLAY
END FOR
END FOR
Records
A record (also called a structured data type or struct) stores multiple related values of different data types under one name. Each piece of data is called a field.
# Define a student record structure
RECORD Student
name : String
age : Integer
score : Real
passed : Boolean
END RECORD
# Create a student record
SET s.name TO "Alice"
SET s.age TO 16
SET s.score TO 87.5
SET s.passed TO TRUE
Arrays vs Records
| Feature | Array | Record |
| Data types stored | Same type for all elements | Different types for different fields |
| Access method | By index (e.g. scores[2]) | By field name (e.g. student.name) |
| Best used for | Lists of similar items (e.g. 30 scores) | Related properties of one entity (e.g. a student's details) |
📝 Exam Tip: 2D array questions often ask you to identify the value at a given [row][col] position. Remember: first index = row, second index = column. Edexcel indexes from 0.
⚠️ Common Mistakes
- Using index 1 as the first position — Edexcel 4CP0 arrays start at index 0
- Confusing rows and columns in 2D arrays — grid[row][col], not grid[col][row]
- Using arrays to store different data types — arrays store one type only; use a record for mixed types