A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-7.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6typeAccstruct{
7Sum,Countint
8}
9m:=map[string]Acc{}
10a:=m["x"]
11a.Sum+=5
12fmt.Println(a.Sum,m["x"].Count)
13}
Maps
Answer & explanation
Console output
5 0
Why
m["x"] is absent, so it returns a copy of the zero Acc value {0 0}. Assigning that to a and doing a.Sum += 5 changes only the local copy, giving a.Sum = 5. The map is never written, so m["x"] still reads as the zero struct and .Count is 0. Map values are not addressable, which is why you must reassign the whole struct to persist changes.