Junior — Senior
The impact of append and element modifications on the original slice
livecode
Task condition
Let's consider an example that shows how changing slice elements and applying the append function inside a passed function affect the slice itself. Determine what output will be obtained at each stage of program execution.
func main() {
mutate := func(a []int) {
a[0] = 0
a = append(a, 1) // ?
fmt.Println(a) // ?
}
a := []int{1, 2, 3, 4}
mutate(a)
fmt.Println(a) // ?
}