Open utterances-bot opened 2 years ago
大佬,猜一下结果是什么
func main() { s := make([]int, 0) //s = []int{0, 10, 100} s = append(s, 0) s = append(s, 10) s = append(s, 100) fmt.Printf("main 内存地址:%p\n", s) hello(s) fmt.Println(s[0:len(s)]) fmt.Println(cap(s)) fmt.Println(s[0:cap(s)]) }
func hello(s []int) { fmt.Printf("hello 内存地址:%p\n", s) s = append(s, 1000) s = append(s, 10000) s = append(s, 100000) s = append(s, 1000000) s = append(s, 10000000) s[0] = 1000 }
图挂了
Go 切片这道题,吵了一个下午!
https://eddycjy.com/posts/go/slice-discuss/