Basic Types
/* * Basic types and operators. A nonsense program. */ package main import "fmt" func main() { // Integer types, and specific-size integers. var a int var b int = 17 c := 10 fmt.Printf("%d + %d + %d = %d\n", a, b, c, a+b+c) // Integers use integer division. fmt.Printf("%d/%d = %d\n", b, c, b/c) // Integers with specific sizes are distinct types // which must be explicitly converted. var ( q int16 = 99 s int64 = 199 ) s = int64(int16(a + 3) + q + 10) fmt.Printf("%d %d\n", q, s) // Floats do, but conversion must be explicit. f := float32(b) / float32(c) fmt.Printf("%d/%d = %.2f\n", b, c, f) // The character constant is a represents its UTF-8 code (which // will be an ASCII byte value if it's an ASCII character). var yum byte = 67; // Code for 'g' capu := 'U'; fmt.Printf("%c %c %c %c\n", yum, capu, yum + 1, capu + ('a'-'A')) }