Originally Posted by
Kempelen
I know how to property initialize a 1 dimensiona array, i.e.:
Code:
int x[3] = {0, 1 , 2};
But how can I initialize de values of :
Code:
int x[3][3] = {?????}
or
Code:
int x[2][4] = {???????}
Like this:
Code:
int x[][] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
In the initialization process, the number of rows and columns will be counted up for you, if you leave the square braces, empty. You can do this only ONCE, after that, you usually use a loop:
Code:
for(row = 0, yourVariable = 1; row < MaxRows; row++) {
for(col = 0; col < MaxCols; col++) {
x[row][col] = yourVariabe++;
}
}