Arrays


Arrays are an important part of Pascal. You can think of them like a catalogue of information. Arrays are declared under the type section. They are a collection of a number of variables, arranged in the form of a table.

type

.....

This is an example of declaring an array in the type block. The array called 'integerArray' is like a list of integers, if seen on paper it might look like this...

1.______20
2.______145
3.______39
4.______2708
5.______25
6.______260
-
-
-
30._____300

The array called integerTable can be represented by a table. It is a two dimensional array. You can have three,four or even five dimensions in an array if you want.


Accessing Arrays


To access an entry of an array during the program you must go...arrayname[entrynumber]
or to access a multi-dimensional array you go...arrayname[x,y,z] (3d array)

OK HERE COMES AN EXAMPLE PROGRAM

Program classTest;
{An example program demostration arrays}
{Takes scores from a class test and tells people if they passed or not}

uses Crt;

type

var

begin

end.

Arrays can also be declared in the variables section without making a type. However it is better to use a type if you plan to use the same type of array in multiple places. So this code in the last program...

type

var

Can also be written like this:

var

This would do exactly the same thing, but does not declare a type of 'testScores'.


Previous Lesson(flow control)    Main Menu    Next Lesson(records)