I never understand why we did v.size( )-1 for travesrsing whole vector it is not string why we do that

i never understand why we did v.size( )-1 for travesrsing whole vector it is not string why we do that

@Aditya-Kushwaha-914550392281281 index starts from 0, so for eg if size = 4
then the indices would be 0,1,2,3. notice here that the last index is size-1. It is just like arrays.

but when we perform d. insert (d.begin() +3,100) then it will perform like 1 2 3 100 4 5 this shows itv runs from i=1

@Aditya-Kushwaha-914550392281281 in the example that you gave,
100 is at the 3rd index, you gave that address in the iterator. This again shows that indexing starts from 0.

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.