// `l.end()` points after the last element, so in principle you need:
for(i=l.end()-1; i!=l.begin(); i--) // invalid
/*
* but then you'll not get the first element (`l.begin()`) as you stop
* when you reach it.
*
* Further it is not valid to subtract 1 from a list iterator so it must
* be:
*/
for(i=std::prev(l.end()); i!=l.begin(); i--) // valid
/*
* But still you have the problem with the first element.
*
* **A better way is to use reverse iterator**. Something like:
*/
for (std::list<int>::reverse_iterator i = l.rbegin(); i != l.rend(); ++i)
// For your second question you could do:
auto it = l.begin();
cout << *(std::next(it, 2));
/*
* Here is a list of valid operations depending on iterator type:
* http:www.cplusplus.com/reference/iterator/
*
* And here you can see that list has a bidirectional iterator:
* http:www.cplusplus.com/reference/list/list/
*
* [4386427] [so/q/32547166] [cc by-sa 3.0]
*/
$
cheat.sh