Skip to content

Instantly share code, notes, and snippets.

@lalizita
Created October 13, 2022 02:26
Show Gist options
  • Save lalizita/c02390e1987769163189cf055b64d9c2 to your computer and use it in GitHub Desktop.
Save lalizita/c02390e1987769163189cf055b64d9c2 to your computer and use it in GitHub Desktop.
default zero values for go
var i int // 0
var f float64 // 0.0
var b bool // false
var s string // ""
fmt.Printf("%v %v %v %q\n", i, f, b, s)
// nil for interfaces, slices, channels, maps, pointers and functions.
var pa *Student // pa == nil
pa = new(Student) // pa == &Student{"", 0}
pa.Name = "Alice" // pa == &Student{"Alice", 0}
b := Student{ // b == Student{"Bob", 0}
Name: "Bob",
}
pb := &Student{ // pb == &Student{"Bob", 8}
Name: "Bob",
Age: 8,
}
c := Student{"Cecilia", 5} // c == Student{"Cecilia", 5}
d := Student{} // d == Student{"", 0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment