What is const_iterator

A const_iterator is not a const iterator. That is,

const vector<int>::iterator it;


vector<int>::const_iterator it;

are different. The first type (const iterator) does not allow any kind of modification of the iterator as well as the contents. That is, both



*it = 40 are illegal.

The second type(const_iterator) allows modification of the iterator, but prevents the contents from getting modified.


++it is legal whereas *it = 40 is illegal.


using namespace std;

int main()


   vector<int> myVector;



   vector<int>::const_iterator it = myVector.begin();

   ++it;       // Legal 

   *it = 40;   // Illegal

   return 0;



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: