🐹 Go (Golang)
Beginner
What is the init function in Go?
Answer
The init() function is a special function that runs automatically before main() — it is called by the Go runtime after all variable initializations in the package are complete. A package can have multiple init() functions across multiple files; they all run in the order the files are presented to the compiler. Common uses include registering drivers (sql.Register), validating configuration, setting up global state, and initializing caches. You cannot call init() explicitly — it is only invoked by the runtime.
Previous
How do constants and iota work in Go?
Next
What is the difference between go run and go build?