Go: Default value of struct, string, slice, map

Variables declared without an explicit initial value are set to their zero values:

This initialization is done recursively; for example each element of an array of structs will have its fields zeroed if no value is specified.

var n int // n == 0
type T struct {
        n int
        f float64
        next *T
t := new(T) // t.n == 0, t.f == 0.0 and t.next == nil


Be the first to comment!