teach-ict.com logo

THE education site for computer science and ICT

2. Introduction to Arrays

Most programs will need to keep track of data. One way to do this is to store the data as independent variables.

Storing the names of players on a football team might look like this:

               player1 "John Smith"

               player2  "Simon Says"

               player3  "Jimmy Widget"
                 ... and so on

So in this example, there would be eleven variables.

The problem with this, is it does not show that there is a relationship between the names - i.e. that they are all part of the same football team.

To do that, you need a better way of organising the data. There are several types of data structure to choose from, but for this task the most suitable is the array.

An array allows you to store related data together as a single collection. For example an array containing 11 elements can be used to store the football team members above.

Another advantage of array is that a number of sorting, searching and updating functions can be applied to it.

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: What is an array