Syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express.For the first syntactic sugar we have to go back in time. In C a[i] is syntactically equivalent to *(a + i) which allows us to write this:
int a[5];but also this:
a[2] = 1;
3[a] = 5;Which more than perfectly illustrates what a syntactic sugar is.
C++11 introduced the range-based for loop:
std::vector<int> v = {0, 1, 2, 3, 4, 5};
for (const int& i : v) // access by const reference
std::cout << i << ' ';