int 变量的大小 [英] size of int variable

查看:29
本文介绍了int 变量的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int 的大小是如何决定的?

How the size of int is decided?

int 的大小是否取决于处理器.对于 32 位机器,它将是 32 位,对于 16 位机器,它将是 16.

Is it true that the size of int will depend on the processor. For 32-bit machine, it will be 32 bits and for 16-bit it's 16.

在我的机器上,它显示为 32 位,尽管机器安装了 64 位处理器和 64 位 Ubuntu.

On my machine it's showing as 32 bits, although the machine has 64-bit processor and 64-bit Ubuntu installed.

推荐答案

这取决于实现.C 标准唯一保证的是

It depends on the implementation. The only thing the C standard guarantees is that

sizeof(char) == 1

sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)

以及类型的一些可表示的最小值,这意味着 char 至少为 8 位长,int 至少为 16 位,等等.

and also some representable minimum values for the types, which imply that char is at least 8 bits long, int is at least 16 bit, etc.

因此它必须由实现(编译器、操作系统、...)决定并记录.

So it must be decided by the implementation (compiler, OS, ...) and be documented.

这篇关于int 变量的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆