go uint 赋值 越界 、 int uint 大小范围
package main import "fmt" func main() { // code 1 var a uint = 0 var b uint = 1 fmt.Println(a - b) // code 2 //a := uint(0) - uint(1) //fmt.Println(a) }
result -> 18446744073709551615
package main import "fmt" func main() { // code 1 //var a uint = 0 //var b uint = 1 //fmt.Println(a - b) // code 2 a := uint(0) - uint(1) fmt.Println(a) }
result -> constant -1 overflows uint(panic)
原因是 在 var 赋值的时候 会做隐适类型 转换 直接转换为 有符号整型了
int 范围 大小
int8. [-128, 127] int16. [-32768, 32767] int32. [-2147483648, 2147483647] int64. [-9223372036854775808, 9223372036854775807]
uint 范围 大小
uint8. [0, 255] uint16. [0, 65535] uint32. [0, 4294967295] uint64. [0, 18446744073709551615]
邮箱: 1090055252@qq.com