/* * Type inference in Go. * Type inference is ONLY on variable declaration * @author gtowell * Created: Aug 19, 2021 */ package main import "fmt" func main() { a := "asdf" fmt.Printf("%s\n", a) // must be a string or the %s would not work b := 32 // inferred to "int" int is either 32 or 64 bits -- compiler choice bl := 300000000000000 // still an "int" but stored in 64 bits! fmt.Printf("bl=%d\n", bl) var c int16 = 16 // c = b // not allowed fmt.Printf("b=%d c=%d\n", b, c) f := 4.56 // inferred to float64 var g float32 = 5.67 // g = f // not allowed fmt.Printf("f=%f g=%f", f, g) }