Arrays are known as a data structure as they can hold more than one value. In order to fully understand arrays it is best to start off with an example.

Name

Test 1

Test 2

Bert

8

3

Fiona

5

7

Sally

7

6

George

7

7

Fred

5

4

We could store these in variables as follows :-


Name1 = "Bert"
Test1a = 8 
Test1b = 3 

Name1 = "Fiona" 
Test1a = 5 
Test1b = 7 
# etc

This means that by the end we will have 15 separate variables. This is clearly not a good way to store this information. What happens if there was 100 students? We would have 300 variables. By using arrays we can store the above information in just 3 arrays.


Names[0] = "Bert"
Test1[0] = 8 
Test2[0] = 3 

Names([] = "Fiona"
Test1[1] = 5 
Test2[1] = 7 
# etc

This is much more efficient. What we have effectively done is created a one dimensional table (or just a single column) to store our data in. We have assigned a name to the array, given it a size and then placed data within it. We can draw these arrays in diagram form

Array

Position

1

2

3

4

Names array

5

Value

Bert

Fiona

Sally

George

Fred

 

Array

Position

1

2

3

4

Test1 array

5

Value

8

5

7

7

5

 

Array

Position

1

2

3

4

Test2 array

5

Value

3

7

6

7

4