Is range based for loop and normal index for loop are same in c++

47 Views Asked by At

So i used a code to to reverse array something like this

for(vector<int> i:matrix)reverse(i.begin(),i.end());

but the output of this is not a reversed array at all, but when i does the same thing with index based loop it worked flawlessly

for(int i{0};i < matrix.size();i++)
{
    reverse(matrix[i].begin(),matrix[i].end());
}

Why is this haappening?

So i used the above to rotate the row of matrix, but they didn't worked even though i defined a custom reverse function to reverse a array then also it doesn't worked

0

There are 0 best solutions below