xxxxxxxxxx
var a bool = true // Boolean
var b int = 5 // Integer
var c float32 = 3.14 // Floating point number
var d string = "Hi!" // String
xxxxxxxxxx
uint8 // the set of all unsigned 8-bit integers (0 to 255)
uint16 // the set of all unsigned 16-bit integers (0 to 65535)
uint32 // the set of all unsigned 32-bit integers (0 to 4294967295)
uint64 // the set of all unsigned 64-bit integers (0 to 18446744073709551615)
int8 // the set of all signed 8-bit integers (-128 to 127)
int16 // the set of all signed 16-bit integers (-32768 to 32767)
int32 // the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64 // the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)
float32 // the set of all IEEE-754 32-bit floating-point numbers
float64 // the set of all IEEE-754 64-bit floating-point numbers
complex64 // the set of all complex numbers with float32 real and imaginary parts
complex128 // the set of all complex numbers with float64 real and imaginary parts
byte // alias for uint8
rune // alias for int32
xxxxxxxxxx
func main() {
// Basic types
var b bool = true
var i int = 42
var f float64 = 3.14
var c complex128 = cmplx.Sqrt(-1)
var s string = "hello"
// Composite types
var arr [3]int = [3]int{1, 2, 3}
var sl []int = []int{1, 2, 3}
var m map[string]int = map[string]int{"one": 1, "two": 2}
type Person struct {
Name string
Age int
}
var p Person = Person{Name: "Alice", Age: 30}
// Pointers
var pi *int = &i
// Functions
var add func(int, int) int = func(x, y int) int {
return x + y
}
// Interfaces
type Stringer interface {
String() string
}
// Channels
var ch chan int = make(chan int)
fmt.Println(b, i, f, c, s)
fmt.Println(arr, sl, m)
fmt.Println(p)
fmt.Println(pi, *pi)
fmt.Println(add(3, 4))
fmt.Println(ch)
}