There are 4 differents ways to iterate through an array.
FIRST
// C style
for(int i=0; i<list.size(); i++)
list[i] = 0;
SECOND
//copies each elemenet in the list to x
for(auto x:list)
x = 0;
THIRD
//using reference declaration,
//which makes x an alias for each element in the list
//if x is built-in type(int, bool, etc) it doesn't make a big difference in time efficiency
for(auto &x:list)
x = 0;
FOURTH
//x is declared as const
//x is only readable
for(const auto &x: list)
cout << x;
Second, third, and fourth loops are called “range-based” for loops (using auto specifiers).
If we iteratre through an object for which begin() and end() memeber functions are defined,
below is also possible
for(auto it=list.begin(); it!=list.end(); ++it)
cout << *it;
This is useful when used with containers like map or set.