1-D array
1-D Arrays allow programmers to store data in a list (provided that the data is of the same data type).
For example, to store a list of Scottish cities you could create a 1-D array.
A programmer can define the number of variables held in a list when they create a 1-D array.
Index
An index is created to be able to identify each variable in the list. The index will start at the value 0.
Eg to store the name of Scottish cities, a 1-D array could be created with seven different index values that identify each item of data. In reference language this could be represented as:
DECLARE scottishCities INITIALLY ["Glasgow", "Dundee", "Perth", "Aberdeen", "Stirling", "Edinburgh", "Inverness"]
Scottish cities | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
Glasgow | Dundee | Perth | Aberdeen | Stirling | Edinburgh | Inverness |
Scottish cities | |
---|---|
0 | Glasgow |
1 | Dundee |
2 | Perth |
3 | Aberdeen |
4 | Stirling |
5 | Edinburgh |
6 | Inverness |
Number of elements
It is common to identify the number of elements that need to be stored in the array when you use software development langugages.
Eg a 1-D array for Scottish cities held in Visual Basic could be represented as:
Dim scottish_cities (7) as String
The value shown in brackets determines the number of elements that are held within the 1-D array.