A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-10.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6a:=make([]int,2,2)
7b:=append(a,5)
8b[0]=9
9fmt.Println(a[0],b[0])
10}
Slices
Answer & explanation
Console output
0 9
Why
When append has no spare capacity (len == cap), Go allocates a new, larger backing array and copies the elements into it. The returned slice b points at that fresh array, so b and a no longer share storage. Mutating b[0] leaves a[0] at its zero value of 0.