[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
arrays Lists of Variables Data Structure
Pascal allows the definition (as variables and/or data types) of
arrays of one or more dimensions. The general format is:
type
<tname> = array[<index>] of <basetype>;
var
<vname> : array[<index>] of <basetype>;
where <tname> and <vname> are identifiers for data types and
variables, respectively. <index> is one or more ranges of ordinal
types and <basetype> is any data type name or declaration (including
another array).
<index> can be defined one of two ways. First, it can be two values
separated by two periods, that is, <val1>..<val2>, where <val1> and
<val2> are any two values of the same ordinal data type (Integer,
Char, Boolean, or enumerated). <val1> has to be less than or equal to
<val2>.
The second method is to replace <index> with the name of some ordinal
type (Char, Boolean, or enumerated; Integer is too large). For
example, replacing <index> with Char will define an array of 256
bytes, since the Char type can take 256 different values.
The largest allowed index range is 32,768 values, while the largest
possible array is 64K bytes.
Multi-dimensional arrays can be declared in one of three ways:
array[<index1>] of array[<index2>] ... of array[<indexN>] of
<basetype>;
array[<index1>][<index2>]...[<indexN>] of <basetype>;
array[<index1>,<index2>,...,<indexN>] of <basetype>;
Similarly, you can refer to a multi-dimensional element in a given
array two different ways:
<vname>[I][J]...[N]
<vname>[I,J,...,N]
-------------------------------- Example ---------------------------------
var
Iota : array[1..10] of Char;
Able : array['A'..'Z'] of Integer;
Fred : array[-5..5,2..9,'a'..'z'] of string[5];
begin
Iota[3] := 'Q';
Able['R'] := 421;
Fred[-3,7,'k'] := 'Help!';
Fred[3][8]['b'] := 'What';
end.
See Also:
array
strings
packed
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson