Is there a three-dimensional Pascal array? If yes, please give an example of use.

program maasss; var a: array[1..10,1..10,1..10] of byte; begin writeln(a[5,5,5]); end. 

Result 0. I do not understand

  • one
    @insolor, well, I can somehow imagine a 3-dimensional array, could you show me a picture of 4 and 5-dimensional array?))) - Gorets
  • 2
    Yes, the 2-dimensional array is 2D (square), three-dimensional - 3D (cube), and four-dimensional - 4D (four dimensions ???) - platinumsemen
  • one
    @Gorets, a 5-dimensional array is just a two-dimensional array of 3-dimensional arrays :) - insolor
  • cap, and 5d is 5 measurements? Unrepresented ... =) - Gorets
  • 3
    In order not to cause a pattern break in your head, imagine a 6-dimensional array as a 3-dimensional array of 3-dimensional arrays. 9-dimensional as a 6-dimensional array of 3-dimensional arrays, etc. - ReinRaus

5 answers 5

Here is another illustrative example for which you can use multidimensional arrays. Actually, of course, for this purpose now use a DB. Suppose you want to collect statistics on forum members. First you have two indicators: forums and cities. With the help of a two-dimensional array, you can describe what forum from which cities how many users have registered.

alt text

Further you want to describe users more detailed. For example, by occupation. So that it would be fashionable to find out how many participants from city A, registered on forum A, are representatives of group C:

alt text

The result was a three-dimensional array. The simplest thing that comes to mind next is to determine the same thing, only dividing by time. That is, separately for 2012, 2011, 2010, etc. The 4-dimensional array will turn out:

alt text

    'Result 0. I do not understand anything'

    this is also clear. When creating new integers, their default value is 0 and when creating a string their default value is '' that is, an empty string. The same basic rules!

    • so this is all in a 3 = x dimensional array - platinumsemen
    • at least in the million-dimensional base of it is the number - then the default value of the measure of the array = 0! And for what minusuete? who should be so minus is the author of the question for the stupidity that he asks! In my opinion - Rules

    Exists. And four-dimensional too. And even five-dimensional, but hardly such arrays are used somewhere in practice. Declared / used quite similar to the 2-dimensional.

    UPD. Here is an illustration of 4 and 5-dimensional arrays:

    picture link

    Unlike infinite spatial dimensions, arrays are finite, so nothing prevents to arrange "side by side" with each other.

    UPD2. Code example:

     program maasss; var a: array[1..10,1..10,1..10,1..10,1..10] of byte; begin a[1,2,3,4,5]:=123; write(a[1,2,3,4,5]); end. 

    I do not know how it is in Turbo Pascal, but it works fine in Free Pascal:

    UPD3. An example of a multi-dimensional array of "life." Suppose the book is a three-dimensional array of letters (3 coordinates - page, line, letter number in a line). Now we take a pile of books - this is already a 4-dimensional array of letters (another dimension is the number of the book in the stack). We put a few piles of books next to it - 5 dimensions. Put the stack in several rows - 6 dimensions. We load books in piles into trucks - the 6th dimension appeared - the number of the truck. Well, and so on.

    • And nevertheless, confirm with the image your answer, at least a five-dimensional array - platinumsemen
    • one
      Take any example on OLAP, multidimensional databases. It will suit you. - angry
    • Program1.pas (2): It was expected of a compiler error for a five-dimensional array - platinumsemen
    • Understood, my fault - platinumsemen

    Pascal 3D array:

     procedure Fnord; const N = 42; type T = array [0..N-1] of array [0..N-1] of array [0..N-1] of Integer; var A: T; begin { ... } A[5,8,2] := 86; { ... } end; 
    • one
      Program1.pas (12): Expected begin - platinumsemen

    Is there a three-dimensional Pascal array? If so, please give an example. program maasss; var a: array [1..10,1..10.1..10] of byte; begin writeln (a [5,5,5]); end. Result 0. I do not understand

    it will be zero, there were no assignments for the elements of the array, so all elements are equal to zero. If you want to see at least some result, do so. program maasss; var a: array [1..10,1..10.1..10] of byte; begin a [5,5,5]: = 23; {this element is assigned the value 23, the remaining elements are equal to zero} writeln (a [5,5,5]); end.