Skip to content
Quiz · Functions as values · lesson 4 of 12

Quiz — a closure counter

What does the program print?

GO
package main

import "fmt"

func main() {
    n := 0
    next := func() int { n++; return n }
    fmt.Println(next(), next(), next())
}

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way