An array is a fixed-size data structure that stores multiple items of the same data type in a sequence. Each item is stored at a specific index position, with the first element at index 0.
nums[0], nums[1], etc.Declare an array of 5 integers:
scores ← [10, 20, 30, 40, 50] OUTPUT scores[0] // Outputs 10 scores[2] ← 99 // Changes index 2 from 30 to 99
FOR i ← 0 TO 4
OUTPUT scores[i]
NEXT i
A 2D array is like a table with rows and columns. Each element is accessed using two indices: array[row][col].
grid ← [[1,2,3],[4,5,6],[7,8,9]] OUTPUT grid[1][2] // Row 1, Column 2 → outputs 6
In some languages, a list is a dynamic structure — it can grow and shrink. In Edexcel 1CP2, the term "array" usually refers to the fixed-size structure. The differences are:
| Feature | Array | List |
|---|---|---|
| Size | Fixed at declaration | Dynamic — can grow/shrink |
| Data types | All elements same type | Can mix types (language-dependent) |
| Access | O(1) random access by index | O(1) random access by index |
| Inserting/deleting | Not straightforward — fixed size | Easier with built-in methods |
array[row][col]8 Edexcel-style questions · AI-marked
nums ← [5, 10, 15, 20, 25]. What is the value of nums[3]?[1]marks with 6 elements (indices 0–5).[3]grid ← [[1,2,3],[4,5,6],[7,8,9]]. What is the value of grid[2][1]?[1]vals with 5 elements.[4]| Term | Definition |
|---|
Timed exam-style test.