$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #232

What is the output?

s := []int{1, 2, 3}
t := s[:2]
t = append(t, 9)
fmt.Println(s)
  1. [1 2 3]
  2. [1 2 3 9]
  3. [1 2 9]
  4. [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 ▸