What are the benefits of using mulit-dimensional arrays? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

What are the benefits of using mulit-dimensional arrays?

In what way could the benefit the programmer, and if you can, would there ever be a point where you would use an array like so: int array[W][X][Y][Z]; Where W, X, Y, and Z are positive integers.

24th Oct 2016, 9:45 PM
Martin Flores
Martin Flores - avatar
2 Antworten
+ 1
Take the chess game, for example. You can use an array chess[8][8], storing pieces in chess[a][b] position for every [a] row and [b] column. But you can also add [c], the number of moves from the beginning, and [d], if you play more games simultaneously. And [e] if there are more players. So: chess[3][5][25][2][4]=1 (with 1=king) will tell you that there is a king in row 4 and column 6, during the move 26 of the 3rd game that is playing the player number 5.
25th Oct 2016, 12:05 AM
marcram
0
Some data is multidimensional. Take space - it has three dimensions, if you add time there are four etc. In general, data, e.g. database entries might have any finite number of dimensions. So if you want to process multidimensional data, multidimensional arrays come in handy.
24th Oct 2016, 9:52 PM
Stefan
Stefan - avatar