Vector problem about expanding size

why in (v.size) after 4 th element ,the size doubles?

hi @ctarun314_5830ac48ebc3bfd4
Kindly share the code u are referring to…

in the video lacture they have made a vector v by using v.push_back(no) ,now if i am doing v.size() that is giving output as 5 but if i am doing v.capacity() its giving output as 8 , they are saying because size of array doubles after 4 but i am not understanding why the size doubles after 4th element enters

my question is how the v.capacity() is 8 as output

basically initially capacity of vector was 4… but on adding 5th element, it directly doubles… there is no exact explanation for why it doubles…
U can read more about vector capacity over here https://www.google.com/amp/s/www.geeksforgeeks.org/vector-capacity-function-in-c-stl/amp/

why the capacity of vector was 4 initially ,is there any reason for that?

No specific reason…

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.