You are on page 1of 5

Data Representation

Arrays
Arrays 1 2 3 4

What is an array? Zoro Ben Jan Ansa

• Is a single data structure that


oContains a collection of related data items of the same type
oAre all stored under a single name
oAre organised in such a way that access to each of the
individual items is possible.

• Every data item of an array has a unique number or index.


• It is created when the program is executed and ceases to exist
when the program is closed.
Properties of an array
• The whole array is given a name – e.g. arrMarks.

• An array can contain a number of values while a simple data type can only
contain a single value. This is why an array is a data structure.
• The contents of each of the individual elements must be of the same data type,
for example all strings or all integers.
• The positions of the elements of the array must be numbered by an enumerated
type such as Integer or Char. These are known as indices of the elements.
Non-enumerated types such as Real and String cannot be used as an index for an array.

• We refer to a specific element in the array by using the name of the array as well
as the index of the element in the array. E.g arrMark[10]
Declaration of an array
var
arrName : array[Lower bound .. Upper bound] of <data type>;

arrName is the name of the array


Lower bound is the index of the first memory position of the array and
Upper bound refers to the last position.
Lower bound and Upper bound must be of an ordinal data type and are separated by two
dots (full stops).
Upper bound must always be larger than Lower bound
<data type> refers to the type of data items in the array and can be any available data type
in programming language.

You might also like