Data Structures
Data Structures
The last option modifies the starting value and the ending value of the indices,
but the number of elements still remains the same.
In the above declaration, the array index starts from 0 to 4 and are
integer values. The memory locations will be as follows:
The five individual locations are Names (0), Names (1), Names (2),
Names (3) and Names (4).
Each data item is called an element of the array. To reference a
particular element one must use the appropriate index.
NB: However, most programming languages differ with Microsoft Visual basic in
handling arrays, especially on the amount of memory allocated. For example, using
Java, the following declaration:
Int [4 ]Names;
This array declaration creates exactly 4 memory spaces for the array Names. The
indices of the array range from 0 to 3 which are
Names[0], Names[1], Names[2] and Names[3]
One-dimensional arrays
A one-dimensional array is a data structure in which the array is
declared using a single index and can be visually represented as a list.
Two-dimensional arrays
A two-dimensional array is a data structure in which the array is
declared using two indices and can be visually represented as a table.
Indices 0 1 2 3
0 Makombe Tinashe M 4A
1 Vheremu Alex M 4B
2 Mununi Mary F 3C
3 Chirongera Salpicio M 2C
4 Mutero Violet F 4C
The diagram above shows the visual representation of a 2 dimensional
array Names(4,3)- 5 rows and 4 columns:
Initialising an array
Initialising an array is a procedure in which every value in the array is
set with starting values – this starting value would typically be “” for a
string array, or 0 for a numeric array.
The above algorithm will shift elements of the array up (or left), removing
the first element and then completely removing the last element in the array.
This allows the user to create the array when he/she actually needs it, using
a ReDim statement: Dynamic arrays can be re-created at will, each time with
a different number of items. When you re-create a dynamic array, its
contents are reset to 0 (or to an empty string) and you lose the data it
contains. If you want to resize an array without losing its contents, use the
ReDim Preserve command:
ReDim Preserve Names(20) As String