Tell me why he writes that an undeclared identifier, because I announced everything?

var n,m:integer; massivCHisel : array [ n,m ] of integer; 

The error is in the array "array [ n,m ]" .

  • Constants are required, not variables. - smackmychi
  • what else? - Igor_bogun
  • 3
    @Igor_bogun well, here you are trying to specify unknown values ​​in advance. This time. Second: please pay attention to what kind of error the compiler writes to you. Answer the question what are n and m? Are they constants? What is indicated in square brackets when declaring an array variable? - smackmychi

1 answer 1

The point here is this. In contrast to C-like languages ​​in pascal / delphi, declaring an array implies specifying not the size of the array, but the starting and ending indices. That is, if you need a two-dimensional array of size n x m, then it should be declared like this:

 massivCHisel : array [1..n, 1..m] of integer; 

if you wanted to create a one-dimensional array with indices from n to m, then so:

  massivCHisel : array [n..m] of integer; 

But that's not all. Such an array declaration assumes that the values ​​of its indices are known at the compilation stage, that is, the above entries are still not correct, since m and n are not constants, but variables. In order to compile the example, you need to do something like:

 const n = 5; m = 6; var massivCHisel : array [1..n, 1..m] of integer; 

If you are interested in the possibility of defining the boundaries of an array using variables, then it makes sense for you to look towards dynamic arrays

  • Indeed, something I hurried with my comment. - smackmychi
  • Just add - I will not say for pascal, and in Delphi it is quite possible for you to create arrays with the size of an enumeration or a boolean type. array[TFonstStyle, Boolean] of - Kromster Sept