Avatar
Fernando Vásquez is an electronics engineer and software developer currently based in the world. He occasionally blogs about Python and Android programming.

Go Types

Signed Integers

  • int, according to the OS: 32 or 64 bits
  • int8
  • int16
  • int32
  • int64

Unsigned Integers

  • uint, according to the OS: 32 or 64 bits
  • uint8
  • uint16
  • uint32
  • uint64

Floating Point

  • float32
  • float64

Summary

Type Example Declaration Example Initialization
Integer var x int x := 42
Floating Point var y float64 y := 3.14
Boolean var flag bool flag := true
String var s string s := "Hello, Go!"
Character Not a separate type ch := 'A'
Array var arr [3]int arr := [3]int{1, 2, 3}
Slice Not a type; dynamic sizing slice := []int{1, 2, 3}
Map var m map[string]int m := make(map[string]int)
Struct type Person struct { Name string; Age int } person := Person{Name: "Alice", Age: 30}
Pointer var ptr *int x := 42; ptr := &x
Function func add(a, b int) int { ... N/A (functions are declared, not initialized)
Interface Not a type; abstract type N/A (interfaces are implemented, not initialized)

Remember that Go is statically typed, so you declare the type of a variable when you first create it using the var keyword or the := shorthand for variable declaration and initialization.

all tags