var a = make([]int, 5, 10) //创建切片,长度为5,容量10
fmt.Println(a)
for i := 0; i < 10; i++ {
a = append(a, i)
}
fmt.Println(a)
fmt.Println(cap(a))
go语言之“输出一组切片查看其容量“
最新推荐文章于 2023-08-31 16:30:09 发布
var a = make([]int, 5, 10) //创建切片,长度为5,容量10
fmt.Println(a)
for i := 0; i < 10; i++ {
a = append(a, i)
}
fmt.Println(a)
fmt.Println(cap(a))