Learning Objectives
- Declare and use one-dimensional arrays.
- Use a variable as an array index.
- Read and write array elements with iteration.
- Apply standard processing patterns to arrays.
Key Terms
- Array
- A fixed collection of elements of the same data type under one identifier.
- One-dimensional array
- An array accessed using one index.
- Element
- One stored item in an array.
- Index
- The integer position used to access an element.
- Index range
- The lowest and highest permitted indexes.
- Out-of-range access
- Attempting to use an index outside the declared range.

Purpose Of A 1D Array
An array stores many related values of the same data type without requiring a separate variable name for every item. Marks[1], Marks[2] and Marks[3] are elements of one Marks array.
The index identifies an element. A variable can be used as the index, allowing a loop to process every element with the same statements.
Arrays are useful for lists such as names, temperatures or scores when the program must keep the values for later processing.
Declaration
The declared range determines the valid indexes. Cambridge permits the first index to be zero or one. Follow the range stated in the question and use it consistently.
Every element has the same data type. A single array cannot directly mix INTEGER, STRING and BOOLEAN elements.
DECLARE Marks : ARRAY[1:30] OF INTEGER
DECLARE Names : ARRAY[0:9] OF STRING
Writing And Reading Elements
An array element can be used wherever a variable of the element type is valid: in input, output, assignment, expressions and conditions.
Marks is the whole array identifier; Marks[Index] is one element. A value assigned to one element does not change the others.
Marks[1] <- 72
OUTPUT Marks[1]
INPUT Marks[Index]
Input And Output With Iteration
The first loop writes into every element. The second reads every element. The loop boundaries exactly match the array range.
DECLARE Index : INTEGER
FOR Index <- 1 TO 30
OUTPUT "Enter mark ", Index
INPUT Marks[Index]
NEXT Index
FOR Index <- 1 TO 30
OUTPUT Marks[Index]
NEXT Index
Processing Arrays
Standard methods can be applied to arrays. A total loop adds Marks[Index]; a search compares each element with a target; a maximum loop updates the current maximum.
The values remain stored after a loop, so the array can be processed several times. This is different from using one variable for repeated input, which loses each previous value.
Index Safety
An index must remain inside the declared range. For ARRAY[1:30], indexes 0 and 31 are invalid. A loop from 1 TO 30 is correct; a loop from 0 TO 30 is not.
An index is normally INTEGER. A REAL index such as 2.5 does not identify an array position.
Array Example Trace
| Index | Marks[Index] |
|---|---|
| 1 | 67 |
| 2 | 81 |
| 3 | 54 |
| 4 | 90 |
Worked Examples
Average Of Ten Values
Question: Store ten REAL measurements and calculate their average.
- Declare Measurements : ARRAY[1:10] OF REAL.
- Initialise Total to zero.
- Use a FOR loop to input each element and add it to Total.
- Calculate Average <- Total / 10.
Answer: The array preserves all ten measurements while the accumulator finds their total.
Find A Name
Question: Search Names[1:20] for Target and set Found to TRUE when matched.
- Initialise Found to FALSE.
- Loop through valid indexes.
- Compare Names[Index] = Target.
- Set Found to TRUE on a match.
Answer: A linear search uses the index variable to inspect each element.
Examination Guidance
- Match loop boundaries to the declared index range.
- State that all elements share one data type.
- Use a variable index in repeated processing.
- Distinguish the array from one element.
- Keep indexes integer and in range.
Common Mistakes
- Assuming the first index is always zero.
- Using one variable name per value instead of an array.
- Accessing Marks[31] in an array ending at 30.
- Declaring mixed element types.
- Forgetting brackets around the index.
Knowledge Check
1. What is a 1D array?
2. Can the first index be zero or one?
3. How is one element accessed?
4. Why are loops useful with arrays?
5. What happens to previous values in an array?