Created
October 13, 2022 02:26
-
-
Save lalizita/c02390e1987769163189cf055b64d9c2 to your computer and use it in GitHub Desktop.
default zero values for go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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