Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do we mean by "dimension" when talking about arrays?"

Tags:

arrays

c

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?

like image 830
user366312 Avatar asked Dec 04 '11 15:12

user366312


1 Answers

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. :-)

like image 106
T.J. Crowder Avatar answered Sep 28 '22 01:09

T.J. Crowder