What an array is and why we use them
Many values of the same type stored under one name.
An array is a data structure that holds multiple values of the SAME data type, accessed by an index.
Without arrays β to store 30 student names you'd need 30 separate variables (Name1, Name2, ..., Name30). Reading them in: 30 lines of input. Looping over them: impossible.
With an array β one declaration holds all 30. Loops can process all of them in three lines.
Cambridge declaration syntax:
DECLARE Names : ARRAY[1:30] OF STRING
This creates a 1D array of 30 strings, indexed 1 to 30.
Reading and writing elements:
Names[5] β "Aisha" // write to position 5
OUTPUT Names[5] // read from position 5
Why arrays matter.
- One loop processes all elements β no per-variable code.
- Algorithms like search and sort become possible.
- Memory layout is contiguous β fast access.
Cambridge tip. Mark scheme expects students to DECLARE the array properly with size AND type. Missing either loses marks.
- Array = N values, same type, one name.
- Indexed access: Arr[i].
- Cambridge arrays typically start at index 1.