A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-58.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6a:=make([]int,1,1)
7a[0]=1
8b:=append(a,2)
9a[0]=50
10fmt.Println(b[0])
11}
Slices
Answer & explanation
Console output
1
Why
Because a is at full capacity, append allocates a new backing array and copies the existing element into it; b no longer shares storage with a. The later a[0] = 50 mutates only a’s original array, so b[0] still reflects the value captured at append time: 1.