The only difference between the following two code snippets is the use of the link. I understand why the first fragment does not compile, and I am looking for help in understanding why the second is compiled.
The first fragment:
int a[2][3] = {0,1,2,3,4,5}; for (auto row : a) for (auto column : row) cout << column << endl;
The above code does not compile because the type 'row' is a pointer to an int, which is not a sequence.
Second snippet:
int a[2][3] = {0,1,2,3,4,5}; for (auto &row : a) for (auto column : row) cout << column << endl;
This code compiles. If I understand correctly how auto works, 'row' is a reference to a pointer to an int. But why can this link be considered as a sequence more than a regular pointer?
source share