Need more clarity on iterators

Need more clarity on iterators like why we use them and how they make our programe simple and efficient

C++ Iterators

Iterators are just like pointers used to access the container elements.

Important Points:

  • Iterators are used to traverse from one element to another element, a process is known as iterating through the container .
  • The main advantage of an iterator is to provide a common interface for all the containers type.
  • Iterators make the algorithm independent of the type of the container used.
  • Iterators provide a generic approach to navigate through the elements of a container.

Advantages:
It is convenient to use iterators rather than using a subscript operator[] to access the elements of a container. If we use subscript operator[] to access the elements, then we need to keep the track of the number of elements added at the runtime, but this would not happen in the case of an iterator.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.