# Idiot question about multidimensional arrays

This is a discussion on Idiot question about multidimensional arrays within the C Programming forums, part of the General Programming Boards category; Definition of two-dimensional array: data_type array_name[row_size][column_size]; This: Code: int table[2][3] = { {0,0,0},{1,1,1} }; works. Why? This should mean a ...

1. ## Idiot question about multidimensional arrays

Definition of two-dimensional array:

data_type array_name[row_size][column_size];

This:
Code:
`int table[2][3] = { {0,0,0},{1,1,1} };`
works. Why? This should mean a size 2 row and a size 3 column, shouldn't it?

Doing this:
Code:
`int table[2][2] = { {0,0,0},{1,1,1} };`
or this:
Code:
`int table[2] = {0,0,0};`
does not work. What's the obvious answer here? Why is a size of 3 for rows written as 2 in the 2-dimensional array?

2. Arrays start their index at 0, so for an array of three elements in would be: int table[2]; with the individual elements table[0], table[1], and table[2].

Take a look at the tutorial

3. Well, your subsets are your rows. So in your first example you have two rows, three columns each. Each subset is a row.

In your second example you are providing two rows of three elements in a 2D array that has 2 columns only.

In your last example you have a 1D array of 2 elements and you are initializing it to contain 3.

4. Originally Posted by AndrewHunter
Arrays start their index at 0, so for an array of three elements in would be: int table[2]; with the individual elements table[0], table[1], and table[2].

Take a look at the tutorial
Wrong. When you allocate memory you get as many as you ask for. So int table[2] is actually an array containing 2 elements [0] and [1].

5. Oh right, sorry I don't know what I was thinking. Thanks claudiu.

6. I know that indexes start at zero, of course.

Ah, dagn - I get it.

Code:
`int table[2][3] = { {0,0,0},{1,1,1} };`
000 is row one, 111 is row two, of course.

Thanks :-)