Skip to content

Data Types

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.

Golang by www.golangdev.cn edit