Skip to content

Data Types ​

Before You Start

  • Applies to: Go 1.21+ (examples verified with Go 1.22) · Prerequisites: Basic Syntax · Read time: about 4 min

Below are all the built-in types in Go for reference. For more details, visit Reference Manual - Types.

Boolean Type ​

Boolean type only has true and false values.

TypeDescription
booltrue is truthy, false is falsy

TIP

In Go, integer 0 does not represent false, and non-zero integers do not represent true. Numbers cannot replace boolean values for logical judgment. They are completely different types.

Integer Types ​

Go assigns different types for integers of different bit lengths, mainly divided into unsigned integers and signed integers.

NumberType and Description
uint8Unsigned 8-bit integer
uint16Unsigned 16-bit integer
uint32Unsigned 32-bit integer
uint64Unsigned 64-bit integer
int8Signed 8-bit integer
int16Signed 16-bit integer
int32Signed 32-bit integer
int64Signed 64-bit integer
uintUnsigned integer, at least 32 bits
intInteger, at least 32 bits
uintptrEquivalent to unsigned 64-bit integer, but specifically for pointer arithmetic to store raw pointer addresses.

Floating Point Types ​

IEEE-754 floating point numbers, mainly divided into single-precision floating point and double-precision floating point.

TypeType and Description
float32IEEE-754 32-bit floating point
float64IEEE-754 64-bit floating point

Complex Types ​

TypeDescription
complex12864-bit real and imaginary
complex6432-bit real and imaginary

Character Types ​

Go strings are fully compatible with UTF-8.

TypeDescription
byteEquivalent to uint8, can represent ANSCII characters
runeEquivalent to int32, can represent Unicode characters
stringString is a byte sequence, can be converted to []byte type (byte slice)

Derived Types ​

TypeExample
Array[5]int, integer array of length 5
Slice[]float64, 64-bit floating point slice
Mapmap[string]int, map with string keys and int values
Structtype Gopher struct{}, Gopher struct
Pointer*int, a pointer to an integer
Functiontype f func(), a function type with no parameters and no return value
Interfacetype Gopher interface{}, Gopher interface
Channelchan int, integer channel

Zero Values ​

The official documentation calls zero values "zero value". Zero value is not just the number zero literally, but rather the empty value or default value of a type.

TypeZero Value
Numeric types0
Boolean typesfalse
String types""
ArrayCollection of zero values of the corresponding type with fixed length
StructStruct with all fields set to zero values
Slice, map, function, interface, channel, pointernil

nil ​

nil is similar to none or null in other languages, but not exactly the same. nil is only the zero value of some reference types and does not belong to any type. From the source code, you can see that nil is just a variable.

go
var nil Type

And statements like nil == nil cannot be compiled.

Complete Example ​

The program below runs as-is: copy it into a file and execute go run main.go, or paste it into the Go Playground.

go
package main

import "fmt"

func main() {
	var (
		b   bool    = true
		i   int     = 42
		i8  int8    = 127
		u8  uint8   = 255
		f   float64 = 3.5
		s   string  = "go"
		r   rune    = '中'
		by  byte    = 'A'
	)

	fmt.Println(b, i, i8, u8, f, s)
	fmt.Printf("rune %c is code point %d\n", r, r)
	fmt.Printf("byte %c = %d\n", by, by)

	// Different numeric types never mix implicitly
	ratio := float64(i) / 8
	fmt.Println(ratio)

	// Unsigned overflow wraps around at runtime
	var small uint8 = 255
	small++
	fmt.Println(small)
}

Expected output:

text
true 42 127 255 3.5 go
rune 中 is code point 20013
byte A = 65
5.25
0

Common Pitfalls ​

  • There is no implicit numeric conversion. int and int64 cannot be added directly; convert one side explicitly.
  • int width is platform dependent (32-bit on some targets, 64-bit on others). Use fixed-size types such as int64 for files and network protocols.
  • Runtime integer overflow wraps silently; constant overflow is a compile error. Validate input when precision matters.
  • byte is an alias of uint8, rune is an alias of int32. Indexing a string gives a byte, not a rune, which breaks non-ASCII characters.
  • Floating-point equality is unreliable. Compare with an epsilon or the math package; note that NaN != NaN.

Change Log ​

  • 2026-10-14: Added "Before You Start" notes, a complete runnable example with expected output, common pitfalls, and this change log.

Golang by www.golangdev.cn · Adapted in part from Golang 中文学习文档 (MIT, © 寒江蓑笠翁)