# Thread: just checking i have this 2d array right

1. ## just checking i have this 2d array right

as the title says have i got this finally into my thick skull!

Code:
// element [0][0] here
// |
//  v
int illegal_squares[8][8] = {{1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1}};
// ^
// |
//  element[7][7] here
is this correct or have i messed up again
many thanks
coop

2. Yes, that's correct. It might be less confusing to use a non-square matrix, so you can see which dimension is which:
Code:
int arr[4][2] {
{0, 0}, // [0][0], [0][1]
{0, 0}, // [1][0], [1][1]
{0, 0}, // [2][0], [2][1]
{0, 0}  // [3][0], [3][1]
};

3. thanks that's a good idea i keep thinking i have mine wrong no matter how many rude comments i leave myself
coop

4. Just remember to index it with illegal_squares[y][x], not illegal_square[x][y].

5. Originally Posted by gaxio
Just remember to index it with illegal_squares[y][x], not illegal_square[x][y].
That just depends on what exactly are x and y meant to be used for. illegal_square[x][y] can be perfectly fine.