Back to questions
JuniorTheoryCommon
What does the program print?
package main
import "fmt"
func main() {
var i int
var s string
var b bool
fmt.Printf("%d %q %t\n", i, s, b)
}0 "" false
- Expecting
<nil>for the string: the zero value ofstringis the empty string"", and%qprints it as""; astringcan never benil. - Expecting a compile error for reading variables never assigned: every variable declared without a value starts at its type's zero value and can be read.
- What would
fmt.Println(i, s, b)print for the same three variables? - What is the zero value of a
float64and of a pointer?