python int占几个字节
发布时间:2025-09-18 14:08:39

《对计算机系统的深入理解》一书提到,int类型在32台机器和64台机器中占据4个字节。《The C Programming language》在这本书中,有一句话是这样的:Each compiler is free to choose appropriate sizes for its own hardware, subject only to the restriction that shorts and ints are at least 16bits, longs are at least 32bits, and short is no longer than int, which is no longer than long.这意味着编译器可以根据自己的硬件选择合适的尺寸,但需要满足约束:short和int型至少有16位,long型至少有32位,short型的长度不能超过int型,int型不能超过long型。也就是说,每种类型的变量长度都是由编译器决定的,而当前的主流编译器通常是32台机器和64台机器,int型是4个字节(例如,GCC)。
相关推荐:Python教程
以下是GCC编译器下32位机器和64位机器各类变量的字节数:

需要注意的是,指针类型存储指向变量的地址,因此32台机器只需要32台,而64台机器需要64台。
下一篇 返回列表
