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.
| Type | Description |
|---|---|
bool | true 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.
| Number | Type and Description |
|---|---|
uint8 | Unsigned 8-bit integer |
uint16 | Unsigned 16-bit integer |
uint32 | Unsigned 32-bit integer |
uint64 | Unsigned 64-bit integer |
int8 | Signed 8-bit integer |
int16 | Signed 16-bit integer |
int32 | Signed 32-bit integer |
int64 | Signed 64-bit integer |
uint | Unsigned integer, at least 32 bits |
int | Integer, at least 32 bits |
uintptr | Equivalent 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.
| Type | Type and Description |
|---|---|
float32 | IEEE-754 32-bit floating point |
float64 | IEEE-754 64-bit floating point |
Complex Types
| Type | Description |
|---|---|
complex128 | 64-bit real and imaginary |
complex64 | 32-bit real and imaginary |
Character Types
Go strings are fully compatible with UTF-8.
| Type | Description |
|---|---|
byte | Equivalent to uint8, can represent ANSCII characters |
rune | Equivalent to int32, can represent Unicode characters |
string | String is a byte sequence, can be converted to []byte type (byte slice) |
Derived Types
| Type | Example |
|---|---|
| Array | [5]int, integer array of length 5 |
| Slice | []float64, 64-bit floating point slice |
| Map | map[string]int, map with string keys and int values |
| Struct | type Gopher struct{}, Gopher struct |
| Pointer | *int, a pointer to an integer |
| Function | type f func(), a function type with no parameters and no return value |
| Interface | type Gopher interface{}, Gopher interface |
| Channel | chan 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.
| Type | Zero Value |
|---|---|
| Numeric types | 0 |
| Boolean types | false |
| String types | "" |
| Array | Collection of zero values of the corresponding type with fixed length |
| Struct | Struct with all fields set to zero values |
| Slice, map, function, interface, channel, pointer | nil |
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.
var nil TypeAnd 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.
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:
true 42 127 255 3.5 go
rune 中 is code point 20013
byte A = 65
5.25
0Common Pitfalls
- There is no implicit numeric conversion.
intandint64cannot be added directly; convert one side explicitly. intwidth is platform dependent (32-bit on some targets, 64-bit on others). Use fixed-size types such asint64for files and network protocols.- Runtime integer overflow wraps silently; constant overflow is a compile error. Validate input when precision matters.
byteis an alias ofuint8,runeis an alias ofint32. Indexing a string gives abyte, not arune, which breaks non-ASCII characters.- Floating-point equality is unreliable. Compare with an epsilon or the
mathpackage; note thatNaN != NaN.
Change Log
- 2026-10-14: Added "Before You Start" notes, a complete runnable example with expected output, common pitfalls, and this change log.
