I was curious about why we go through a multidimensional array this way
for (auto& row : mat1)
{
for (int& elements : row)
{
cin >> elements;
}
}
Why do we use &(pass by ref) when we make a temp variable called elements that goes through the rows and gets each value. aswell as the & in the for (auto& row : mat1) Can someone explain this whole part with every detail please ?
using namespace std;
int main()
{
const int row{ 3 }, col{ 3 };
array<array<int, col>, row > mat1;
cout << "Enter matrix 1 elements: ";
for (auto& row : mat1)
{
for (int& elements : row)
{
cin >> elements;
}
}
for (auto& row : mat1)
{
for (int& elements : row)
cout << elements << " ";
cout << endl;
}