What is the output?
s := []int{1, 2, 3}
t := s[:2]
t = append(t, 9)
fmt.Println(s)
- [1 2 3]
- [1 2 3 9]
- [1 2 9]
- [1 2 9 3]
t shares s's backing array and still has spare capacity, so append overwrites s[2] in place.
Play Problem Solving ▸
s := []int{1, 2, 3}
t := s[:2]
t = append(t, 9)
fmt.Println(s)