To loop over a 3x3 array called "a" in C++ i used the following code.
int a[3][3] {};
for(auto &b: a) {
for(auto &c: b) {
std::cout << c << std::endl;
}
}
If I had to replace the "auto", I would intuitively try
int a[3][3] {};
for(int &(b[3]): a) {
for(int &c: b) {
std::cout << c << std::endl;
}
}
But this does not work. Instead I figured out that the following works.
int a[3][3] {};
for(int (&b)[3]: a) {
for(int &c: b) {
std::cout << c << std::endl;
}
}
So the question is: Why does the latter example work?
I thought I needed a reference to an array of length 3, but instead I need an array of length 3 containing references.