go 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位,但是又不是int32的别名

unsafe.Sizeof()

// Sizeof takes an expression x of any type and returns the size in bytes
// of a hypothetical variable v as if v was declared via var v = x.
// The size does not include any memory possibly referenced by x.
// For instance, if x is a slice, Sizeof returns the size of the slice
// descriptor, not the size of the memory referenced by the slice.
// The return value of Sizeof is a Go constant.
func Sizeof(x ArbitraryType) uintptr

1byte=8bit

func main()  {
	var x int = 100
	fmt.Println(unsafe.Sizeof(x)) // 8
	var y int64 = 1
	fmt.Println(unsafe.Sizeof(y)) // 8
	var y1 int32 = 1
	fmt.Println(unsafe.Sizeof(y1)) // 4
	var z uint64 = 1
	fmt.Println(unsafe.Sizeof(z)) // 8
	var z1 uint32 = 1
	fmt.Println(unsafe.Sizeof(z1)) // 4
}

// 结果
8
8
4
8
4

我看有相关文章在说这个值与go的版本有关。。。

你可能感兴趣的:(go,后台)