• 技术文章 >Python技术 >Python基础教程

    python int占几个字节

    爱喝马黛茶的安东尼爱喝马黛茶的安东尼2019-09-21 17:47:19原创6279

    《深入理解计算机系统》这本书上面提到了在32位机器和64机器中int类型都占用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位机器只需要32bit,而64位机器需要64bit。

    专题推荐:python int 字节
    上一篇:python如何定义和调用函数 下一篇:python中conn是什么

    相关文章推荐

    • python中判断一个数是否为int

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网