Creating an Array: Difference between revisions
Content deleted Content added
→{{header|AppleScript}}: ++ amigae |
m →{{header|Pascal}}: no third level long lines; rm delphi specific (moving to delphi header) |
||
Line 568: | Line 568: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
'''Using a fixed length array as global or stack variable''' |
|||
<lang pascal> |
<lang pascal> |
||
var |
var |
||
Line 581: | Line 581: | ||
</lang> |
</lang> |
||
'''Dynamically allocating a fixed length array on the heap''' |
|||
<lang pascal> |
<lang pascal> |
||
type |
type |
||
Line 595: | Line 595: | ||
</lang> |
</lang> |
||
'''Defining a variable-length array''' |
|||
{{works with|Extended Pascal}} |
|||
<lang pascal> |
<lang pascal> |
||
type |
type |
||
Line 616: | Line 619: | ||
</lang> |
</lang> |
||
Note that also the lower index may be given as dynamic argument. |
Note that also the lower index may be given as dynamic argument. |
||
=== Defining a variable-length array (Delphi) === |
|||
<lang pascal> |
|||
var |
|||
i: integer; |
|||
a: array of integer; |
|||
begin |
|||
readln(i); |
|||
SetLength(a, i); { create array } |
|||
a[0] := 2; { use it } |
|||
if high(a) = i |
|||
then |
|||
writeln('I expected that.'); |
|||
else |
|||
writeln('Get a better compiler!'); |
|||
finalize(a); |
|||
end |
|||
</lang> |
|||
Delphi dynamic arrays have base 0 index. |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |