19.1 What is an Array?
- An array is a collection of variables of the SAME type, stored under ONE name.
- Each element is reached using an INDEX (position number).
- CIE pseudocode uses 1-based indexing — the first element is at index 1.
- Arrays let you store many related values without declaring separate variables for each one.
DECLARE Numbers : ARRAY[1:5] OF INTEGER
Numbers[1] <- 10
OUTPUT Numbers[1]Key idea: Think of an array as a row of labelled boxes. The name tells you which row, and the index tells you which box.
What is an Array?
19.2 Declaring and Initializing Arrays
- Declaration syntax:
DECLARE <name> : ARRAY[<start>:<end>] OF <type> - The start index is usually 1 in CIE pseudocode.
- Arrays can hold
INTEGER,REAL,STRING,BOOLEANorCHARvalues.
Initializing with a loop (input from user):
DECLARE Numbers : ARRAY[1:5] OF INTEGER
DECLARE I : INTEGER
FOR I <- 1 TO 5
OUTPUT "Enter number: "
INPUT Numbers[I]
NEXT IInitializing with specific values:
DECLARE Days : ARRAY[1:7] OF STRING
Days[1] <- "Monday"
Days[2] <- "Tuesday"
Days[3] <- "Wednesday"
Days[4] <- "Thursday"
Days[5] <- "Friday"
Days[6] <- "Saturday"
Days[7] <- "Sunday"Exam tip: When a question asks you to “populate” an array, use a FOR loop with INPUT. When the values are fixed (like day names), assign each one explicitly.
Declaring and Initializing Arrays
19.3 Accessing Array Elements
- Access an individual element with its index:
Numbers[3] - Access every element using a FOR loop and a counter variable as the index.
OUTPUT Numbers[1]prints the first element.- Common operations include printing all elements, finding a specific element and counting elements.
DECLARE Numbers : ARRAY[1:5] OF INTEGER
DECLARE I : INTEGER
FOR I <- 1 TO 5
OUTPUT Numbers[I]
NEXT ICommon mistake: Writing Numbers(I) with parentheses. CIE uses square brackets — Numbers[I] — for array indexing.
Accessing Array Elements
19.4 Input and Output with Arrays
- Input: loop through the array and INPUT each element by index.
- Output: loop through the array and OUTPUT each element by index.
- Use two separate loops so input and output are clearly separated.
Example: input 5 names and display them
DECLARE Names : ARRAY[1:5] OF STRING
DECLARE I : INTEGER
FOR I <- 1 TO 5
OUTPUT "Enter name: "
INPUT Names[I]
NEXT I
OUTPUT "You entered:"
FOR I <- 1 TO 5
OUTPUT Names[I]
NEXT IKey idea: The loop counter I doubles as the array index. Each pass of the loop reads or prints exactly one element.
Input and Output with Arrays
19.5 Basic Array Operations
- Sum — add every element to an accumulator.
- Count — increment a counter when an element meets a condition.
- Find max/min — track the largest or smallest value seen.
- Search — check whether a value exists in the array.
Example: sum of array elements
DECLARE Numbers : ARRAY[1:5] OF INTEGER
DECLARE I : INTEGER
DECLARE Total : INTEGER
Total <- 0
FOR I <- 1 TO 5
OUTPUT "Enter number: "
INPUT Numbers[I]
Total <- Total + Numbers[I]
NEXT I
OUTPUT "Sum: ", TotalFind maximum
DECLARE Max : INTEGER
Max <- Numbers[1]
FOR I <- 2 TO 5
IF Numbers[I] > Max THEN
Max <- Numbers[I]
ENDIF
NEXT I
OUTPUT MaxCount greater than 10
DECLARE Count : INTEGER
Count <- 0
FOR I <- 1 TO 5
IF Numbers[I] > 10 THEN
Count <- Count + 1
ENDIF
NEXT I
OUTPUT CountCommon mistake: Initialising Max to 0 when the array may contain only negative numbers. Initialise Max to the first element instead.
Basic Array Operations
19.6 Key Points Summary
Arrays store multiple values of the SAME type under one name.
CIE uses 1-based indexing — the first element is at index 1.
Declare with DECLARE <name> : ARRAY[1:N] OF <type>.
Access elements with <name>[<index>] using square brackets.
Use FOR loops to iterate through arrays.
Common operations: sum, count, find max/min, search.
Array size is fixed at declaration time.
Initialise accumulators (Sum, Count) before the loop.
Exam tip: When a question asks you to process every element, reach for a FOR loop from 1 to N — it covers every index and is the standard CIE pattern.