Friday, 30 June 2017

matrix - n-dimensional c++ array. How`s that possible?



I became confused when GCC allowed me to do this:



int t[10][10][10][10][10];



I realize int i[N][N] is an NxN matrix where the first N means the row, and the second means the column. Also, the third N in int i[N][N][N] means depth, giving us a 3d dimensional array.



I do not understand what int i[N][N][N][N] and beyond mean.



The fourth dimension is time, but that does not apply here.



So, could this mean that when I get to the third one, I could let the logic go away?


Answer



I find a library analogy very useful to visualizing arrays of multiple dimensions:





  • 8-dimensional array is a library

  • 7-dimensional array is a floor in a library

  • 6-dimensional array is a room on a floor in a library

  • 5-dimensional array is a bookcase in a room on a floor in a library

  • 4-dimensional array is a shelf in a bookcase in a room on a floor in a library

  • 3-dimensional array is a book on a shelf in a bookcase in a room on a floor in a library

  • 2-dimensional array is a page in a book on a shelf in a bookcase in a room on a floor in a library

  • 1-dimensional array is a line on a page in a book on a shelf in a bookcase in a room on a floor in a library

  • 0-dimensional array is a character in a line on a page in a book on a shelf in a bookcase in a room on a floor in a library



No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...