Gaaker Go

Golang Zero valued

Only declare that the value of the uninitialized variable is zero-valued.

Different data types have different zero values. E.g:

  • The zero value of string type is ""

  • The zero value of an integer (int) is 0

  • The zero value for floats (float32, float64) is 0.0

  • The zero value of bool is false

  • The zero value of map is nil

The following is a complete code example.

package main

import "fmt"

func main() {
    var a string
    var b int
    var c float32
    var d bool

    fmt.Println(a,b,c,d)
}

Below is the program output:

0 0 false
< Zero valued Zero valued >