Previous topic |
Next topic |
Ada Home Page |
Index
Arrays
An array is a data structure
which groups related items together
- related in that they record similar data about several different things
- the mark on a test for each student in a class
- the temperature on the hour, at each hour during a day
- etc
Array index vs. array element
Think of an array as a collection of letter boxes:
- each has a label on it, so each can be identified individually
- numbered from "low" to "high", or 1..8, in the
picture below
- each can store an item of information (the same type of thing in each one)
When designing an array, you need to decide
- what the labels are going to be
- the array index
- what type of value is the index?
- what range of values can the index take?
- the array index may be INTEGER, CHARACTER or any ENUMERATED TYPE
- what type of information can go into each box.
- the array element type
- the array element type can be any type
- the type of the array index is not related to the type of the
array items
Examples
The picture below shows three example array types. They are similar to the
extent that each can store 8 items of data, but they differ in what can be
stored and how each element is labelled:
- INTEGER(1..8)
- element type is INTEGER
- index type is INTEGER
- index can take 8 possible values, ranging from 1..8
- FLOAT('a'..'h')
- element type is FLOAT
- index type is CHARACTER
- index can take 8 possible values, ranging from 'a'..'h'
- STRING(-5..2)
- element type is STRING
- index type is INTEGER
- index can take 8 possible values, ranging from -5..2
Previous topic |
Next topic |
Ada Home Page |
Index
c-lokan@adfa.oz.au / 27 Feb 96