size vs capacity of a vector?

后端 未结 6 1659
刺人心
刺人心 2020-11-27 03:10

I am a bit confused about this both of these look same to me. Although it may happen that capacity and size may differ on different compilers. how it may differ. Its also sa

6条回答
  •  误落风尘
    2020-11-27 03:40

    size() tells you how many elements you currently have. capacity() tells you how large the size can get before the vector needs to reallocate memory for itself.

    Capacity is always greater than or equal to size. You cannot index beyond element # size()-1.

提交回复
热议问题