I just starting to learning vectors and little confused about size()
and capacity()
I know little about both of them. But why in this program both
I think the following question can give you more detail about the capacity of a vector.
About Vectors growth
I will reference the answer in above question.
The growth strategy of capacity
is required to meet the amortized constant time requirement for the push_back
operation. Then, the strategy is designed to have a exponential growth generally when the space is lack. In short, the size
of vector indicate the number of elements now, while the captacity
show its ability used to push_back
in future.