Golang(三)[基本数据类型]

Golang 基本数据类型参考源码:

src/builtin/builtin.go

1.布尔类型(bool)

// bool is the set of boolean values, true and false.
type bool bool

// true and false are the two untyped boolean values.
const (
	true  = 0 == 0 // Untyped bool.
	false = 0 != 0 // Untyped bool.
)
系统架构 字节大小 取值范围 默认值
32/64位 1个字节(1Byte) true/false false

2.整型

1.int

// int is a signed integer type that is at least 32 bits in size. It is a
// distinct type, however, and not an alias for, say, int32.
type int int
符号位 系统架构 字节大小 取值范围 默认值
32位 4个字节(4Byte) -2^(32-1) 到 2^(32-1)-1 0
64位 8个字节(8Byte) -2^(64-1) 到 2^(64-1)-1

2.uint

// uint is an unsigned integer type that is at least 32 bits in size. It is a
// distinct type, however, and not an alias for, say, uint32.
type uint uint
符号位 系统架构 字节大小 取值范围 默认值
32位 4个字节(4Byte) 0到 2^(32-1)-1 0
64位 8个字节(8Byte) 0到 2^(64-1)-1

3.int8

// int8 is the set of all signed 8-bit integers.
// Range: -128 through 127.
type int8 int8
符号位 系统架构 字节大小 取值范围 默认值
32/64位 1个字节(1Byte) -2^(8-1) 到 2^(8-1)-1 0

4.uint8

// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
// used, by convention, to distinguish byte values from 8-bit unsigned
// integer values.
type byte = uint8

其别名byte为一个字节类型
在这里插入图片描述

符号位 系统架构 字节大小 取值范围 默认值
32/64位 1个字节(1Byte) 0到 2^(8-1)-1 0

5.int16

6.uint16

7.int32

在这里插入图片描述

8.uint32

9.int64

10.uint64

3.浮点型

1.float32

2.float64

3.注意事项

4.字节(byte)

5.字符串(string)

上一篇:Golang(二)[IDE配置]
下一篇:Golang(四)[array]

发布了25 篇原创文章 · 获赞 11 · 访问量 2806

猜你喜欢

转载自blog.csdn.net/weixin_42366378/article/details/105003056
今日推荐