A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-150.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6s:="x"
7deferfunc(){fmt.Println(s)}()
8deferfunc(){s="y"}()
9s="z"
10}
Defer
Answer & explanation
Console output
y
Why
Both deferred closures capture the same variable s by reference. At function exit defers run LIFO: first s = "y" executes, then fmt.Println(s) prints the current value "y". The earlier "z" assignment was overwritten before the print ran.