qq_慕圣411555
2019-04-04 16:20
package main import "fmt" func main(){ var n []int printslice(n) n = append(n,0) printslice(n) n = append(n,1) printslice(n) n = append(n,2,3,4) printslice(n) n1 := make([]int,len(n),(cap(n))*2) copy(n1,n) printslice(n1) } func printslice(x []int){ fmt.Printf("len = %d,cap = %d,slice = %d\n",len(x),cap(x),x) len = 0,cap = 0,slice = [] len = 1,cap = 1,slice = [0] len = 2,cap = 2,slice = [0 1] len = 5,cap = 6,slice = [0 1 2 3 4] len = 5,cap = 12,slice = [0 1 2 3 4]
可以看下这篇文章, 有详细解析 https://www.cppentry.com/bencandy.php?fid=78&aid=216871&page=1
Go语言第一课
107794 学习 · 148 问题
相似问题