An array is a group of relatedvariables which have the
samename and datatype.
Each element in an array can be referenced using a
unique number called a subscript or index, which indicates the element’s position in the array.
All array subscripts are positiveintegers.
Arrays can be initialized with values when they are declared using curly braces {}.
The firstsubscript or index of an array is always 0
Array elements can also be accessed by their position within the array using the [] operator.
An array must be declared before it can be used.
To declare an array, you need to specify the array name, the number of elements and the datatype name, the number of elements and the datatype.
For an array of size n, the last element in the array will have subscript n‐1. Eg: size = 10 the indices range is 0-9. Always declare an array with the maximum size you will require as the size remainsstatic once declared.
Data may be inserted into a specific position in an array using the following format:
arrayName[subscript] = expression
Expression may be any combination of constants,
variables and operators.
For example:
Sales[0] = 3.6
Sales[2] = mysales
Sales[1] = 8.9 x 75
Sales[3] = mysales x 2
The Data type of the expression must match the data type of the array elements.
A 2-dimensional array is used to store information that would normally be represented in table form.
All of the data is of the same type (like in one-dimensional arrays).
Example:
Declaration: branchSales[40][14] of type real
or branchsales as array of 40 rows and 14 cols of type integer
Accessing the third branch and first set of sales data branchSales[2][0] = 3549.45
To perform a search of an array, the IF statement and the FOR loop is all you need.