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

October 28, 2007 · Filed Under C++ Questions, Placement Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

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 ();

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email