Skip to the content of the web site.

The parallel between pointers and iterators

The overloading of the unary * operator and the unary ++ and perhaps -- operators may appear convenient, but consider how you would do the same with pointers and older arrays:

    std::size_t const N{ 16 };
    int array[N];
    // Assign the entries of the array...

    // Print the entries of the array
    for ( int *ptr{ array }; ptr != array + N; ++ptr ) {
      std::cout << *ptr << " ";
    }

    std::vector data( N );
    // Assign the entries of the vector...

    // Print the entries of the vector
    for ( auto itr{ data.begin() }; itr != data.end(); ++itr ) {
      std::cout << *itr << " ";
    }

For the array, ptr is initialized with the address of the first entry of the array, and while the address of that pointer is not equal to the entry beyond the end of the array, the body of the loop is executed (in this case, printing what is at that address) and then incrementing the address to point to the next entry of the array.

Thus, you should be able to understand the choice for the notation used to iterate through containers: it was meant to parallel iterating through an older array.