Programming · 4 question types
Past paper frequency (2018 to 2024)
This topic accounts for approximately 5% of your exam marks.
1D array manipulation with FOR loops appears regularly in Paper 2. 4 to 6 marks.
A 1-dimensional array (1D array) is a single row of elements, like a list.
In CIE pseudocode an array is declared with DECLARE, an ARRAY[start:end] size, and a data type:
DECLARE Scores : ARRAY[1:5] OF INTEGER
DECLARE Names : ARRAY[1:10] OF STRING
DECLARE Flags : ARRAY[1:3] OF BOOLEAN
Scores : ARRAY[1:5] OF INTEGER creates an array called Scores with 5 elements (indices 1, 2, 3, 4 and 5), each holding an integer.Names : ARRAY[1:10] OF STRING creates 10 string slots.After declaration, the array exists but the elements have no useful values yet; they need to be assigned.
CIE pseudocode is 1-indexed: the first element is at position 1, the last element at position n (where n is the size).
Python is 0-indexed: the first element is at position 0, the last at position n − 1.
| CIE pseudocode | Python | |
|---|---|---|
| First element of an array of size 5 | arr[1] | arr[0] |
| Last element of an array of size 5 | arr[5] | arr[4] |
Always use 1-indexed in CIE answers unless the question gives an example using a different convention.
Two common ways:
// Assign one element at a time
DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 12
Scores[2] ← 10
Scores[3] ← 5
Scores[4] ← 2
Scores[5] ← 8
// Or assign a whole list in one go
Scores ← [12, 10, 5, 2, 8]
After either of these, Scores contains the five values 12, 10, 5, 2, 8.