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 Number | Type and description |
|---|---|
| 1 | Boolean type Boolean values can only be the constants true or false. A simple example: var b bool = true. |
| 2 | Numeric 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. |
| 3 | String 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. |
| 4 | Derived types: Including:
|
Numeric types
Go also has architecture-based types, such as: int, uint, and uintptr.
| Serial Number | Type and description |
|---|---|
| 1 | uint8 Unsigned 8-bit integer (0 to 255) |
| 2 | uint16 Unsigned 16-bit integer (0 to 65535) |
| 3 | uint32 Unsigned 32-bit integer (0 to 4294967295) |
| 4 | uint64 Unsigned 64-bit integer (0 to 18446744073709551615) |
| 5 | int8 Signed 8-bit integer (-128 to 127) |
| 6 | int16 Signed 16-bit integer (-32768 to 32767) |
| 7 | int32 Signed 32-bit integer (-2147483648 to 2147483647) |
| 8 | int64 Signed 64-bit integer (-9223372036854775808 to 9223372036854775807) |
Floating-point type
| Serial Number | Type and description |
|---|---|
| 1 | float32 IEEE-754 32-bit floating-point number |
| 2 | float64 IEEE-754 64-bit floating-point number |
| 3 | complex64 32-bit real and imaginary numbers |
| 4 | complex128 64-bit real and imaginary numbers |
Other numeric types
The following lists additional numeric types:
| Serial Number | Type and description |
|---|---|
| 1 | byte Similar to uint8 |
| 2 | rune Similar to int32 |
| 3 | uint 32 or 64 bits |
| 4 | int Same size as uint |
| 5 | uintptr Unsigned integer type, used to store a pointer |