What are Iterators in C++ and Object Oriented Programming ? Explain where we use them

 
 

Iterators allow the traversal of a container object. They provide a generic interface to navigate a container without having to know the actual type of its elements. Several member functions of containers like begin () and end () return a pointer to iterators. Begin () returns a pointer to the beginning of a container and end returns a pointer one position past the last valid element of a container. This element past the last element marks the end of the container like a \0 is used to mark the end of strings.
The functions begin () and end () come in two flavors: const and non const. The non cons version returns non const iterator that enables a user to modify the value of its container while const iterators cannot modify its container.

e.g. vector  v1;
	vector ::iterator p = v.begin ();