Go language data types

In the Go programming language, data types are used to declare functions and variables.

Data types exist to divide data into categories with different memory size requirements. When programming, you only need to allocate large memory when large data is needed, thereby making full use of memory.

Go language has the following data types by category:

Serial NumberType and description
1Boolean type
Boolean values can only be the constants true or false. A simple example: var b bool = true.
2Numeric types
Integer type int and floating-point types float32 and float64. Go supports integer and floating-point numbers, and also supports complex numbers, where bit operations use two's complement.
3String type:
A string is a character sequence formed by connecting a series of fixed-length characters. Go strings are made up of individual bytes. The bytes of Go strings use UTF-8 encoding to identify Unicode text.
4Derived types:
Including:
  • (a) Pointer type
  • (b) Array type
  • (c) Structured types (struct)
  • (d) Channel type
  • (e) Function type
  • (f) Slice type
  • (g) Interface type (interface)
  • (h) Map type

Numeric types

Go also has architecture-based types, such as: int, uint, and uintptr.

Serial NumberType and description
1uint8
Unsigned 8-bit integer (0 to 255)
2uint16
Unsigned 16-bit integer (0 to 65535)
3uint32
Unsigned 32-bit integer (0 to 4294967295)
4uint64
Unsigned 64-bit integer (0 to 18446744073709551615)
5int8
Signed 8-bit integer (-128 to 127)
6int16
Signed 16-bit integer (-32768 to 32767)
7int32
Signed 32-bit integer (-2147483648 to 2147483647)
8int64
Signed 64-bit integer (-9223372036854775808 to 9223372036854775807)

Floating-point type

Serial NumberType and description
1float32
IEEE-754 32-bit floating-point number
2float64
IEEE-754 64-bit floating-point number
3complex64
32-bit real and imaginary numbers
4complex128
64-bit real and imaginary numbers

Other numeric types

The following lists additional numeric types:

Serial NumberType and description
1byte
Similar to uint8
2rune
Similar to int32
3uint
32 or 64 bits
4int
Same size as uint
5uintptr
Unsigned integer type, used to store a pointer
other extensions