Default zero values for all Go types

yourbasic.org/golang

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

The elements of an array or struct will have its fields zeroed if no value is specified. This initialization is done recursively:

type T struct {
	n int
	f float64
	next *T
}
fmt.Println([2]T{}) // [{0 0 <nil>} {0 0 <nil>}]

Further reading

Struct initialization code example

Share this page: