Sobes.tech
Middle

What variable types are there in Go?

sobes.tech AI

Answer from AI

In Go, there are several basic variable types:

  • Basic types:

    • bool — logical type (true/false)
    • string — string
    • Integer types: int, int8, int16, int32, int64, as well as unsigned uint, uint8 (alias for byte), uint16, uint32, uint64
    • float32, float64 — floating-point numbers
    • complex64, complex128 — complex numbers
  • Composite types:

    • Arrays and slices ([n]T, []T)
    • Structures (struct)
    • Maps (map[K]V)
    • Interfaces (interface{})
    • Channels (chan T)

Example of declaring variables of different types:

var a int = 10
var b string = "hello"
var c bool = true
var d []int = []int{1, 2, 3}
var e map[string]int = map[string]int{"key": 1}