English 中文(简体)
Go - 数据类型
  • 时间:2024-12-22

Go - Data Types



在Go编程语言中,数据类型是指用于声明不同类型的变量或函数的广泛系统。变量的类型决定了它在存储器中占据的空间以及存储的位模式是如何解释的.

围棋中的类型可分为以下几类 −

Sr.No. Types and Description
1

Boolean types

它们是布尔类型,由两个预定义的常量组成:(a)true(b)false

2

Numeric types

它们又是算术类型,表示整个程序中的a)整数类型或b)浮点值.

3

String types

字符串类型表示字符串值的集合。它的值是一个字节序列。字符串是不可变的类型,一旦创建,就不可能更改字符串的内容。预先声明的字符串类型为字符串。

4

Derived types

它们包括(a)指针类型、(b)阵列类型、(c)结构类型、(d)并集类型和(e)函数类型f)切片类型g)接口类型h)映射类型i)通道类型

数组类型和结构类型统称为聚合类型。函数的类型指定具有相同参数和结果类型的所有函数的集合。我们将在下一节中讨论基本类型,而其他类型将在接下来的章节中介绍。

Integer Types

The predefined architecture-independent integer types are −

Sr.No. Types and Description
1

uint8

Unsigned  8-bit integers (0 to 255)

2

uint16

Unsigned 16-bit integers (0 to 65535)

3

uint32

Unsigned 32-bit integers (0 to 4294967295)

4

uint64

Unsigned 64-bit integers (0 to 18446744073709551615)

5

int8

Signed 8-bit integers (-128 to 127)

6

int16

Signed 16-bit integers (-32768 to 32767)

7

int32

Signed 32-bit integers (-2147483648 to 2147483647)

8

int64

Signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

Floating Types

The predefined architecture-independent float types are −

Sr.No. Types and Description
1

float32

IEEE-754 32-bit floating-point numbers

2

float64

IEEE-754 64-bit floating-point numbers

3

complex64

Complex numbers with float32 real and imaginary parts

4

complex128

Complex numbers with float64 real and imaginary parts

n位整数的值为n位,使用两个s补码算术运算表示.

Other Numeric Types

还有一组具有特定于实现的大小的数字类型 −

Sr.No. Types and Description
1

byte

same as uint8

2

rune

same as int32

3

uint

32 or 64 bits

4

int

same size as uint

5

uintptr

an unsigned integer to store the uninterpreted bits of a pointer value