2.2.3 Arrays
Arrays can be thought
of
as
shelves within the computer's memory which contain rows
of
boxes, each
of
which represents a variable. The boxes on these shelves are arranged in an orderly sequence, and are
identified
by
means
of
numbers; these numbers are referred to
as
subscripts, because
they
are subscripted
to the name which identifies
the
entire group
of
boxes.
Such shelves
of
boxes are set
up
simply
by
executing an instruction which declares
that
they
exist;
this is referred
to
as
making an array declaration. The array declaration specifies
the
number
of
boxes
which are to be included in each set
of
shelves (i.e., the size
of
the shelves) and
the
manner in which
they are
to
be
arranged.
The boxes in each
unit
of
shelves may be arranged in sequences which have any
number
of
dimensions.
Thus, a one-dimensional array can be
thought
of
as
a single shelf which holds, one
row
of
boxes; a two-
dimensional array can be
thought
of
as
a stack
of
shelves, each
of
which holds one
row
of
boxes; and
so forth. These boxes,
or
variables, are referred
to
as
the
array's elements.
The
number
of
subscripts used
to
identify each
of
the
array elements
of
a corresponds to
the
number
of
dimensions in
that
array.
For
example, each
of
the elements in a one-dimensional array is identified
by
a single subscript which indicates
the
box's
position in the row; each
of
the elements in a two dimensional
array is identified
by
two subscripts,
one
which identifies
the
box's
row, and one which indicates the
box's
position within
that
row; and so forth. The numbers which are used
as
the
subscripts start with zero, and
have a maximum value which
is
determined
by
the size
of
each
of
the array's dimensions (i.e.,
the
number
of
boxes in each row, etc.).
The maximum size
of
an array
is
limited
by
the
amount
of
free space which is available in
the
com-
puter's
memory (i.e.,
by
the
size
of
the
program, the
number
of
items
of
data
which are
to
be stored
in
the
array, and
so
forth). The syntax
of
BASIC places
no
restrictions on the
number
of
dimensions
which can
be
used for any array,
but
in practice the
number
of
dimensions is limited
by
the
amount
of
free memory space which
is
available for storage
of
array variables.
An array must
be
declared before values can
be
stored in any
of
its elements.
~~GAC2~
·--·--
GA(IO~
A (100)
The variables making
up an array are referred
to
as its elements.
A
(3, 3, 3)
A one-dimensional array
consisting
of
101 elements.
A (10, 10)
A two-dimensional array
consisting
of
11
x
11
elements.
A three-dimensional array
consisting
of
4 x 4 x 4 elements.
24--------------------------------------------------------------
--
--------