Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array length in Borland Pascal

I don’t understand how the array range really limits me, for example this program

program Test;
  var
    a:integer;
    c:array[1..5] of integer;
  begin
    for a:=0 to 8 do begin
      read(c[a]);
    end;
    for a:=0 to 8 do begin
      writeln(c[a]);
    end;
end.

for input

1 2 3 4 5 6 7 8 9

writes

1 2 3 4 5 6 7 8 9

(all in a new row because of writeln) but the array range should be from 1 to 5. How does it accept more values then? I also tried with Setlength(c,5) but same story.

like image 657
Luka Avatar asked Sep 19 '25 13:09

Luka


1 Answers

  for a:=low(c) to high(c) do
   <code>

Newer delphi's might also allow length, defined as high(c)-low(c)+1

like image 118
Marco van de Voort Avatar answered Sep 21 '25 04:09

Marco van de Voort