go基础第五篇:slice扩容

x := []int{1, 2, 3, 4}
y := x[:2]
fmt.Println(cap(x), cap(y))
y = append(y, 30)
fmt.Println("x:", x)
fmt.Println("y:", y)

 

 

x := []int{1, 2, 3, 4}
y := x[2:]
fmt.Println(cap(x), cap(y))
y = append(y, 30)
fmt.Println("x:", x)
fmt.Println("y:", y)

 

posted on 2024-06-25 09:57  koushr  阅读(8)  评论(0编辑  收藏  举报

导航