What do we mean by "dimension" when talking about arrays?
I understand the idea. But what would be the answer?
For example, int array[5];
I know that, this is a 1D array. It has 1 subscript in the index. But why is it called a 1 Dimensional array? Why not 1 Subscript array?
We say "dimension" because that's the general term for this sort of thing. Think about our world, for instance: It has three readily-apparent dimensions (width, height, depth). Or think of geometry: A point has zero dimensions, a line has one, a plane has two, a cube has three, etc. The terminology applies to arrays because it precisely describes the same thing in relation to the array. The dimensionality of an array is how many axes it has.
A one dimensional array has one axis, like a line:
XXXXXXXX
You index into it with one subscript, e.g. array[n]
.
A two-dimensional array has two axes, like a plane:
XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX
You index into it with two subscripts, e.g. array[x,y]
.
I won't attempt to represent 3+ dimensional arrays (like cubes) with ASCII art. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With