ARRAY PRESENTATION
Array
- An array is a static data structure, which stores and implements a set of items of the
same data type using the same identifier name, in contiguous memory location.
- Every array element is accessed or referenced using an index (subscript), therefore
uses index register addressing.
- It can either store integers, or names, but not both in one unit.
Declaration of arrays using VB 6.0
- Arrays are declared by stating the following parameters:
• array name
• array size
• dimensions
• data type
- The size of the array is the maximum number of elements that it can store.
- For example, the following declares an array that reserves five locations in memory
and labels these as ‘Names’:
Dim Names(4) As String
This can also be declared as
Dim Names(0 to 4 ) As String
One may also declare the array as
Dim Names(1 to 5) As String
- On running, the computer creates 5 contiguous memory locations under the name
“Names”. Thus Names will contain 5 partitions.
- Each memory partition will be accessed using an index, which is the address of the
memory space in the array.
- Array index starts at Zero up to N, N being the number in the declaration of the array.
- In the above declaration, the array index starts from 0 to 4 and are integer values.
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.
- The following diagram shows the visual representation of the array Names(4):
0 Theresa
1 Tinotenda
2 Tariro
3 Laurence
4 Fadzai
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 Manatse Natasha F 6C
1 Muchuwa Julia F 6C
2 Nyamarebvu Zvikomborero M 6S
3 Matizha Kudakwashe M 6S
4 Mandigora Tafadzwa M 6C
- The diagram above shows the visual representation of a 2 dimensional array
Names(4,3)- 5 rows and 4 columns:
- Each individual element can be referenced by its row and column indices. For
example:
Names(0,0) is the data item “Manatse”
Names(2,1) is the item “Zvikomborero”
Names(1,2) is the item “F”
FOR MORE ON HOW TO INTIALISE, SERIAL SEARCH, DELETING,
SORTING AN ARRAY AND THE RELATIVE PSEUDOCODES REFER TO A
LEVEL COMPUTER SCIENCE NOTES 2020 BY MAM MARANGE.