Go 变量声明后若不赋值,各类型默认值
Go 变量声明后若不赋值,各类型默认值(数字类型默认为 0,其他类型为 nil):
| 数据类型 | 默认值 |
|---|---|
| bool | false |
| string | 空字符串 |
| int | 0 |
| float32 | 0 |
| float64 | 0 |
| pointer | nil(空指针) |
| 切片 | nil(长度为 0,容量为 0) |
| map | nil |
| interface | (nil, nil) |
Go 变量声明后若不赋值,各类型默认值(数字类型默认为 0,其他类型为 nil):
| 数据类型 | 默认值 |
|---|---|
| bool | false |
| string | 空字符串 |
| int | 0 |
| float32 | 0 |
| float64 | 0 |
| pointer | nil(空指针) |
| 切片 | nil(长度为 0,容量为 0) |
| map | nil |
| interface | (nil, nil) |