Go basic types
Go’s basic types are
1bool
2
3string
4
5int int8 int16 int32 int64
6uint uint8 uint16 uint32 uint64 uintptr
7
8byte // alias for uint8
9
10rune // alias for int32
11 // represents a Unicode code point
12
13float32 float64
14
15complex64 complex128The example shows variables of several types, and also that variable declarations may be “factored” into blocks, as with import statements. E.g.:
1package main
2
3import (
4 "fmt"
5 "math/cmplx"
6)
7
8// you can factor var statements
9var (
10 ToBe bool = false
11 MaxInt uint64 = 1<<64 - 1
12 z complex128 = cmplx.Sqrt(-5 + 12i)
13)
14
15func main() {
16 fmt.Printf("Type: %T Value: %v\n", ToBe, ToBe)
17 fmt.Printf("Type: %T Value: %v\n", MaxInt, MaxInt)
18 fmt.Printf("Type: %T Value: %v\n", z, z)
19}The int, uint, and uintptr types are usually 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. When you need an integer value you should use int unless you have a specific reason to use a sized or unsigned integer type.
References
#rune #golang #int #basic #type #blocks #float #factored #unsigned #complex