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
Using
std::vector array(10); // make room for 10 elements and initialize with 0
You actually filled all the ten spaces with zeros. Adding ad additional element will cause the capacity to be expanded thanks for efficiency. In your case it is useless to call the function reserve because you have instantiated the same number of elements.
check this and this link