Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Go Language Data Types

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 requiring different memory sizes; when programming, large memory is requested only when large data is needed, thus making full use of memory.

Go has the following data types by category:

No. Type and description
1 Boolean
A Boolean value can only be the constant true or false. A simple example: var b bool = true.
2 Numeric Types
The integer type int and floating-point types float32 and float64. Go supports integer and floating-point numbers as well as complex numbers, and bit operations use two's complement.
3 String Type:
A string is a sequence of characters of fixed length connected together. Go's strings are connected by individual bytes. The bytes of a string in Go use UTF-8 encoding to represent Unicode text.
4 Derived Types:
 包括:     
  • (a) Pointer type
  • (b) Array type
  • (c) Struct type (struct)
  • (d) Channel type
  • (e) Function type
  • (f) Slice type
  • (g) Interface type
  • (h) Map type
  • |

    Numeric Types

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

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

    Floating-point

    No. 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 more numeric types:

    No. 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