This is a creation in Article, where the information may have evolved or changed.
Today's no-smell go into the basics, see the slice as a reference type of description, write code experiment a bit
varSlice1[]int=make ([]int, 4,6)
var slice2 []int = Slice1
FMT. Println (Slice1, slice2) // output Span style= "COLOR: #0800" >[0 0 0] [0 0 0]
Operation Slice1& slice2 See if it affects each other .
slice1[1]= One
slice2[2]=
slice1 = append (Slice1, 33 )
FMT. Println (Slice1, slice2) // output result [0 11 22 0 33] [0 11 22 0]
slice2 = append (Slice2, 44 ) Span style= "COLOR: #0800" >//
Fmt. Println (Slice1,slice2)[022 0 [0] 0]
View output: The reference type of the discovered slice is said to be an assignment, passing in a parameter, only sharing the underlying array, and does not share the quantity variable of two slices
varSlice []int = make([] int , 6,ten)
fmt. Println(slice)[0000 00]
fillslice(slice)
Fmt.Println(Slice)// [0 1 2 3 0 0]/ * Populating the contents of a slice
*/
Funcfillslice (slice[]int){
Slice[0]=0
Slice[1]=1
Slice[2]=2
Slice[3]=3
Slice=append(slice,4 )
Slice=Append (Slice, 5)
Slice=append(slice , 6 )
}