A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-144.go
1packagemain
2
3import"fmt"
4
5typeStackstruct{data[]int}
6
7funcmain(){
8varsStack
9s.data=append(s.data,1,2)
10fmt.Println(s.data,len(s.data))
11}
Classes
Answer & explanation
Console output
[1 2] 2
Why
The zero-value Stack has a nil data slice, which is perfectly usable: append accepts a nil slice and allocates as needed. Appending 1 and 2 produces [1 2] with length 2. This is why zero-value structs containing slices are ready to use without explicit initialization.