samedi 6 janvier 2018

How can I use a range for to traverse an array backwards in C++11? [duplicate]

This question already has an answer here:

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