9618 · 10.2
Arrays
An array is a data structure that stores a collection of items, all of the same type, in a single, named block of memory. You can access any item directly by using its numerical position, called an index.
Need to know
What you need to know
- **Homogeneous Data:** All elements in an array must be of the same data type (e.g., all `INTEGER`, all `STRING`).
- **Single Identifier:** The entire collection of data is referred to by one name.
- **Indexed Access:** Elements are accessed using an integer index, typically enclosed in square brackets, e.g., `MyArray[3]`.
- **Static Size:** In the context of the 9618 syllabus, arrays have a fixed size that is defined when they are declared and cannot change while the program is running.
Explanation
Digital Pigeonholes
- Define the array's structure: its name, size (lower and upper bounds), and the data type it will hold, e.g., `DECLARE Scores : ARRAY[1:50] OF INTEGER`.
- Populate the array with data. This is often done using a loop to read values from a user or a file into each position.
- Access a specific element using its index. For example, `Scores[3]` refers to the third element in the `Scores` array.
- Process the entire array by using a `FOR` loop to iterate from the lower bound to the upper bound, performing an operation on each element in turn.