cap vs len of slice in golang

前端 未结 3 1460
感动是毒
感动是毒 2021-01-31 15:35

What is the difference between cap and len of a slice in golang?

According to definition:

A slice has both a length and a capacity.

The length of a slice

3条回答
  •  一生所求
    2021-01-31 15:54

    You've answered your question - the length of the underlying array in a slice is not necessarily the same as the number of elements that array contains.

提交回复
热议问题