← Back to archive

Stdle #54 · defer · 2026-07-30

What does this Go snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

package main
import "fmt"
type Counter struct{ n int }
func (c Counter) Show() { fmt.Println("n =", c.n) }
func main() {
c := Counter{n: 1}
defer c.Show()
c.n = 99
fmt.Println("set to", c.n)
}
Defer
2 lines
4 attempts left

Answer & explanation