There is any way of making x array constant after the data is read from user? There is any way of making variable not modifiable after it's value is read from user (eg. y)?
program hmm;
uses crt;
var
i, y: word;
x: array of word;
begin
readln(y);
y:=y-1;
SetLength(x,y);
for i := 0 to y do begin
read(x[i]);
end;
readkey;
end.
To make y constant I tried something like this, but it won't work - y will be set as 0.
program hmm;
uses crt;
var
i: word;
x: array of word;
const
{$J+}
y:word = 0;
{$J-}
begin
{$J+}
readln(y);
y:=y-1;
{$J-}
y:=0;
SetLength(x,y);
for i := 0 to y do begin
read(x[i]);
end;
readkey;
end.
Thanks for help.
Yes. Don't change either of them in your code after you set the initial value.
Other than that, there's no way. A dynamic array by definition is changeable, and so is a variable - that's why they have dynamic and variable as names.