Hi,
I am confused about how multi-dimensional arrays are initialized. For instance, if I want to do something to the effect of:
Code:
int a[2][3];
for (int i = 0; i < 2; ++i) {
for (int r = 0; r < 3; ++r) {
a[i][r] = i+r;
}
}
I would imagine that I can initialize a[2][3] like this:
Code:
int a[2][3] = {
{ 0, 1 },
{ 1, 2 },
{ 2, 3 }
};
since a[2][3] can be seen as "an array of 3 elements, each element is an array of 2 elements"?
that is apparently incorrect as my compiler (gcc 4.1) gives me:
Code:
a.cpp:6: error: too many initializers for ‘int [2][3]’
and writing the declaration as
fixes it.
Can you please point out what am I doing wrong?
Thank you very much