fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. array<int, 5> arr = {1, 3, 4, 5, 6};
  6.  
  7. for(auto it = arr.begin(); it!=arr.end(); it++) {
  8. cout << *it << " ";
  9. }
  10. cout << endl;
  11.  
  12.  
  13.  
  14. for(auto it = arr.rbegin(); it != arr.rend(); it++) {
  15. cout << *it << " ";
  16. }
  17. cout << endl;
  18.  
  19. for(auto it = arr.end() - 1; it >= arr.begin(); it--) {
  20. cout << *it << " ";
  21. }
  22. cout << endl;
  23.  
  24. // for each loop
  25. for(auto it: arr) {
  26. cout << it << " ";
  27. }
  28. cout << endl;
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
1 3 4 5 6 
6 5 4 3 1 
6 5 4 3 1 
1 3 4 5 6