/* * Even pointers in Go have zero values!!! * the "zero value" is "nil" @ @author gtowell * created July 28, 2021 */ package main import ( "fmt" ) // A struct // the zero-ing of a structure is the zeroing of all of the elents of the structure type Temp struct { ttt int ptr *int } func (t Temp) String() string { return fmt.Sprintf("ttt:%d ptr:%v", t.ttt, t.ptr); } func main() { var pnt *Temp // pointer tmp0 := Temp{} pnt1 := &tmp0 fmt.Printf("pnt is a nil pointer: %v %p\n", pnt == nil, pnt) fmt.Printf("pnt1 is a nil pointer: %v %p\n", pnt1 == nil, pnt1) fmt.Printf("tmp0 -- each part is initialized to a \"zero\" value %v\n", tmp0) fmt.Printf("tmp0.ptr is also a nil pointer: %v\n", tmp0.ptr == nil) }