anotherSlice := theSlice
anotherSlice = append(anotherSlice, newEle)
fmt.Println(len(anotherSlice) == len(theSlice))
This snippet will output false
. Why?
And here are some other experiments:
package main
import "fmt"
func main() {
theSlice := []int{3,3,2,5,12,43}
anotherSlice := theSlice
fmt.Println(anotherSlice[3], theSlice[3])
anotherSlice[3] = anotherSlice[3]+2
fmt.Println(anotherSlice[3], theSlice[3])
anotherSlice = append(anotherSlice[:3], anotherSlice[4:]...)
fmt.Println(len(anotherSlice),len(theSlice))
}
The output is like below:
5 5
7 7
5 6
Program exited.