Sobes.tech
Junior — Senior

Output of append results and shared memory in slices

livecode

Task condition

Determine which values will be printed by the fmt.Println function, considering the behavior of the append function and how slices share memory.

func a() {
  x := []int{}
  x = append(x, 0)
  x = append(x, 1)
  x = append(x, 2)
  x = append(x, 3)
  y := append(x, 4)
  z := append(x, 5)
  fmt.Println(y, z)
}

func main() {
  a()
}