I am reading C++ Primer and on page 128, it says to avoid array to pointer conversion to use reference like so:
int ia[3][4];
for (const auto &row : ia)
for (const auto &col : row)
cout << col << endl;
Because if written as:
for (auto row : ia)
for (auto col : row)
The program would not compile as the auto will deduce the array as a pointer to int. Then the inner for loop will be attempting to iterate a pointer which is illegal.
However, I previously read on page 118 Pointers Are Iterators that pointers to array elements support iterator operations. So I am confused why iterating a pointer in this case is illegal. My thinking is that the range for is syntactic sugar for the regular for loop, so basically it is still calling the increment operator (++) on the pointer/iterator of the array to iterate over the elements which sounds like it should be able to point to the next element in the array?
1