0984

Arrays

Programming · 4 question types

Exam Frequency Analysis

Past paper frequency (2018 to 2024)

This topic accounts for approximately 5% of your exam marks.

stable
Rare
Stable5%

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 (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.

1-indexed vs 0-indexed

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 pseudocodePython
First element of an array of size 5Arr[1]arr[0]
Last element of an array of size 5Arr[5]arr[4]

Always use 1-indexed in CIE answers unless the question gives an example using a different convention.

The diagram below shows the anatomy of a 0-indexed array of length 5: the first element sits at index 0 and the last at index 4, so an array of size n runs from index 0 to index n − 1.

A 1D array of length 5 holding the letters B, E, A, D, S in cells indexed 0 to 4 across the top; annotations point to the first index (0), the first element (B), the element at index 3 (the 4th element, D), and a double-headed arrow labelled array length is 5
Source: Arrays by Save My Exams
Exam tip

Declaring a 1D array: getting the syntax right

What comes up: questions give you a partial or buggy array declaration and ask you to correct it, or ask you to write a declaration from scratch.

Write: DECLARE Name : ARRAY[1:n] OF TYPE — the colon before ARRAY is required, the bounds use [1:n] for a 1-indexed array of size n, and the data type (INTEGER, STRING, BOOLEAN, REAL) follows OF. Every element must be the same type.

Watch out: the most common error penalised in past papers is omitting the colon (writing DECLARE Name ARRAY[...] instead of DECLARE Name : ARRAY[...]). A second frequent error is choosing the wrong data type (for example, BOOLEAN when the stored values are strings). Index 0 does not exist in CIE pseudocode — using it causes an out-of-range error and loses marks.

Initialising an array with values

In CIE pseudocode, array elements are assigned one at a time, each by its index. There is no whole-array literal: you cannot write Scores ← [12, 10, 5, 2, 8] in CIE pseudocode.

DECLARE Scores : ARRAY[1:5] OF INTEGER
Scores[1] ← 12
Scores[2] ← 10
Scores[3] ← 5
Scores[4] ← 2
Scores[5] ← 8

After this, Scores contains the five values 12, 10, 5, 2, 8. When the values follow a pattern, a FOR loop can assign the elements instead of writing each line out by hand.