Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 200
Patrick Bassut Avatar asked Nov 26 '22 21:11

Patrick Bassut


2 Answers

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
like image 66
Sergey Kalinichenko Avatar answered Nov 29 '22 11:11

Sergey Kalinichenko


In the world of mathematics, the number of dimensions doesn't matter. It just eventually gets to a point at which one can no longer visualize it.

like image 39
jrad Avatar answered Nov 29 '22 12:11

jrad