This is a creation in Article, where the information may have evolved or changed.
1.
slice1:= Slice[0:2]
References, not duplicates, so any modifications to Slice1 or slice will affect each other.
Data: = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}data1: = data[0:2]data1[0] = 99fmt. Println (data1) fmt. PRINTLN (data)
[99 2]
[99 2 3 4 5 6 7 8 9 0]
2.Append
Append more Special
Statement:
SOURCE slice= src
Add slice = App
Result Slice=tar
1) If Len (src) + len (APP) <= cap (SRC) src and tar are pointing to the same data reference, i.e. modifying src or tar, will affect each other
2) Otherwise tar is a copy of the way src + app, ie modify SRC or tar, does not affect each other
In either case, the app will not be affected because the app will go to tar using copy
Func test2 () {Data: = make ([]int, Ten,] data[0] = 1data[1] = 2dataappend: = Make ([]int, ten, +)//len <=10 then result[0] = 99 will affect source slicedataappend[0] = 1dataappend[1] = 2result: = Append (data, dataappend ...) Result[0] = 99result[11] = 98fmt. Println ("Length:", Len (Data), ":", data) fmt. Println ("Length:", Len (Result), ":", result) fmt. Println ("Length:", Len (Dataappend), ":", Dataappend)}