i don't know whether its done through the iterator but yes this statement does set the vector value at 3rd position to 999. how does it matter whether its through iterator or not?
Doesn't the begin function return an iterator, and the vector container happens to have an algorithm for pointer arithmetic? I've tried adding and subtracting with other container iterators but they don't work.
Doesn't the begin function return an iterator, and the vector container happens to have an algorithm for pointer arithmetic? I've tried adding and subtracting with other container iterators but they don't work.
It works for random access iterators, which a vector has and many other containers do not. A pointer satisfies the criteria for a random access iterator.
operator []( n ) is described in terms of semantics as returning *(a.begin() + n). However it is not necessary that it indeed uses expression *(a.begin() + n). The only requirements that operator []( n ) will be semantically equivalent to expression *(a.begin() + n).