大概代码如下
```golang
func main() {
old := make([]string, 0, 10)
fmt.Printf("old address: %p\n", old)
old = append(old, "one")
fmt.Printf("old address: %p\n", old)
add(old)
fmt.Println(old)
}
func add(temp []string) {
fmt.Printf("temp address: %p\n", temp)
temp = append(temp, "end")
fmt.Printf("temp address: %p\n", temp)
fmt.Println(temp)
}
结果如下:
old address: 0xc00009ad20
old address: 0xc00009ad20
temp address: 0xc00009ad20
temp address: 0xc00009ad20
[one end]
[one]
```
开始我make时故意将cap设置成10,就想它们共用一块内存, 从结果来看确实也是共用的一块,但old输出的值为何不是两个呢
哪个大侠对方面理解很深入的话帮忙解释一下吧,谢了
有疑问加站长微信联系(非本文作者)