Confused about append() behavior on slices
问题 func main() { slice := make([]int, 10, 10) slice[0] = 0 slice[1] = 1 slice1 := slice slice1[0] = 10000 fmt.Println(slice) slice1 = append(slice1, 100) slice1[0] = 20000 fmt.Println(slice) } result: [10000 1 0 0 0 0 0 0 0 0] [10000 1 0 0 0 0 0 0 0 0] In my understanding, slice is a pointer, slice1 and slice point to the same array, and the first output also proves this. But why did slice 's value remain unchanged after the append operation changed slice1 ? 回答1: The append() didn't change