vector< int > v;
v.reserve(100);
for(int i=0;i<100;i++)
v[i] = i;
cout<<v.size();
then v.size give output zero but actually it must be print
100 because i initilized the memory by 0 to 99
vector< int > v;
v.reserve(100);
for(int i=0;i<100;i++)
v[i] = i;
cout<<v.size();
then v.size give output zero but actually it must be print
100 because i initilized the memory by 0 to 99
hello @khemchandrs
a) that loop is just placing value at address v.begin()+i.and we are not getting error becuase we have reserved first 100 locations .starting from v.begin().
b) in order to reflect changes in ur size u need to use push_back function
read about reserve and resize function.
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.