This question already has an answer here:
- C++11 reverse range-based for-loop 6 answers
This is how I traverse an array from first to last element:
#include <iostream>
using namespace std;
int main()
{
int a[4]={0,1,2,3}, i=0;
for (auto i : a)
cout << i << " ";
cout << endl;
return 0;
}
Is is possible to traverse it backwards using the same loop? And if so, how?
Aucun commentaire:
Enregistrer un commentaire