Zero values

Variables declared without an explicit initial value are given their zero value.

The zero value is:

  • 0 for numeric types,
  • false for the boolean type, and
  • "" (the empty string) for strings.

zero.go

  1. package main
  2. import "fmt"
  3. func main() {
  4. var i int
  5. var f float64
  6. var b bool
  7. var s string
  8. fmt.Printf("%v %v %v %q\n", i, f, b, s)
  9. }