Table of contents
In the Go programming language, data types are used to declare functions and variables.
The emergence of data types is to divide data into data with different required memory sizes. When programming requires large data, it is only necessary to apply for large memory, so that the memory can be fully utilized.
The Go language has the following data types by category:
serial number | type and description |
---|---|
1 | Boolean The Boolean value can only be the constant true or false. A simple example: var b bool = true. |
2 | The number type is integer type int and floating point type float32, float64. Go language supports integer type and floating point type numbers, and supports complex numbers, and the bit operation adopts complement code. |
3 | String type: A string is a sequence of characters connected by a string of fixed-length characters. Go strings are concatenated from individual bytes. The bytes of strings in the Go language use the UTF-8 encoding to represent Unicode text. |
4 | Derived types: include: * (a) pointer type (Pointer) * (b) array type* (c) structured type (struct) * (d) Channel type* (e) function type* (f) slice type* ( g) interface type (interface) * (h) Map type |
number type
Go also has schema-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
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
Other more numeric types are listed below:
serial number | type and description |
---|---|
1 | byte is similar to uint8 |
2 | rune is similar to int32 |
3 | uint 32 or 64 bit |
4 | int is the same size as uint |
5 | uintptr unsigned integer, used to store a pointer |