📜  Go-数据类型

📅  最后修改于: 2020-11-04 06:25:16             🧑  作者: Mango


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

Go中的类型可以分类如下-

Sr.No. Types and Description
1

Boolean types

They are boolean types and consists of the two predefined constants: (a) true (b) false

2

Numeric types

They are again arithmetic types and they represents a) integer types or b) floating point values throughout the program.

3

String types

A string type represents the set of string values. Its value is a sequence of bytes. Strings are immutable types that is once created, it is not possible to change the contents of a string. The predeclared string type is string.

4

Derived types

They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types f) Slice types g) Interface types h) Map types i) Channel Types

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

整数类型

预定义的与体系结构无关的整数类型是-

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)

浮动类型

预定义的与体系结构无关的浮点类型为-

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位,并使用二进制的补码算术运算表示。

其他数值类型

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

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