I have learned how to print out each element in a two-dimensional array
int arr[3][3] = {....};
for ( auto &row : arr){
for ( auto col : row)
cout<<col<<endl;
}
I understand that the &row in the outer for loop has to be a reference. Otherwise, row will become a pointer pointing to array arr's first element which is an array of 3 ints.
Based on this, I thought the following code could work but it didn't
for( auto row : arr ){
for ( auto col:*row)
cout<<col<<endl;
}
It gives me the error about the inner for loop
no callable 'begin' function found for type 'int'
Did I miss something here?
row
is a pointer, not an array (in the code that gives the error).