Why Vector's size() and capacity() is different after push_back()

前端 未结 6 742
鱼传尺愫
鱼传尺愫 2021-01-03 00:09

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

6条回答
  •  感动是毒
    2021-01-03 00:49

    It is for efficiency so that it does not have to expand the underlying data structure each time you add an element. i.e. not having to call delete/new each time.

提交回复
热议问题