What is the output?
for i := 0; i < 3; i++ {
defer fmt.Print(i)
}
- 012
- 0
- 210
- 222
Deferred calls run last-in, first-out when the function returns, and each captured i at defer time.
Play Problem Solving ▸
for i := 0; i < 3; i++ {
defer fmt.Print(i)
}