#include #include using namespace std; /* Three ways to loop through the elements of an array. Use the first loop if you need the subscript of each element as well as the vale of each element. In the second loop, el is a copy of each element of the array. The ++el increments the copy, but this has no effect on the array element. In the third loop, el is each element of the array. The ++el increments the element. */ int main() { int a[] {10, 20, 30}; const size_t n {size(a)}; //the number of elements in the array for (int i {0}; i < n; ++i) { cout << i << " " << a[i] << "\n"; } cout << "\n"; for (auto el: a) { cout << el << "\n"; ++el; //Why bother to increment a variable that's about to die? } cout << "\n"; for (auto& el: a) { cout << el << "\n"; ++el; } cout << "\n"; for (auto el: a) { cout << el << "\n"; //Demonstrate that the above ++ worked. } return EXIT_SUCCESS; }