总结如果改变了原本的值,切片的值也会跟着变,如果改变了切片的值,原本的值也会跟着变,所以有指针特性,其实slice的底层存储就是数组。go语言的slice是并不是纯引用类型,而是一种包含指针的聚合类型,类似type IntSlice struct{ ptr *int len int cap int}因为类似struct,所以还是值传递样例1·测试程序 package main import “fmt” func main(){ a :=[…]int{0,1,2,3,4,5,6,7,8,9} fmt.Println(a) s1:=a[:] s2:=s1[:] fmt.Println(s1) fmt.Println(s2) fmt.Println("") fmt.Println("——————————-") fmt.Println("") a[9]=10 s2[0]=100 fmt.Println(a) fmt.Println(s1) fmt.Println(s2) }输出[0 1 2 3 4 5 6 7 8 9][0 1 2 3 4 5 6 7 8 9][0 1 2 3 4 5 6 7 8 9]——————————-[100 1 2 3 4 5 6 7 8 10][100 1 2 3 4 5 6 7 8 10][100 1 2 3 4 5 6 7 8 10]分析0全变100了9全变10了样例2测试程序package mainimport “fmt"func add1(s []int,x int) []int{ s=append(s,x); return s}func add2(s []int,x int){ s=append(s,x);}func main(){ a :=[…]int{0,1,2,3,4,5,6,7,8,9} fmt.Println(a) s1:=a[5:8]//len=3 cap=5 fmt.Println(s1) add2(s1,0) fmt.Println(a) fmt.Println(s1) add2(s1,1) fmt.Println(a) fmt.Println(s1)}输出[0 1 2 3 4 5 6 7 8 9][5 6 7][5 6 7][0 1 2 3 4 5 6 7 0 9][5 6 7][0 1 2 3 4 5 6 7 1 9]分析数组的 8依次变成了 0、1但slice s1始终没变说明slice并不是纯引用类型