int类型12345678

占据多少字节?

共 2 个回复


jimmykuu

int 类型跟平台有关,在32位平台就是32位,64位平台就是64位。

# 0

wangboo

func main() {
    var a int = 0
    var b int32 = 0
    var c int64 = 0
    fmt.Printf("len int(%d), int32(%d), int64(%d)\n",
        unsafe.Sizeof(a), unsafe.Sizeof(b), unsafe.Sizeof(c))
}
-bash-3.2$ go run a.go
len int(8), int32(4), int64(8)
# 1