是用C默认长整型诠释? [英] is int by default long int in C?

查看:106
本文介绍了是用C默认长整型诠释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么说我发现int和long int的长度都显示为4个字节?难道int是默认长整型?


解决方案

 的sizeof(短)< = sizeof的(INT)< = sizeof的(长)

这就是你可以指望。剩下的就是完全取决于执行。在DOS下的昔日,16位编译器通常的sizeof(int)的==的sizeof(短)== 2.在32位系统上,的sizeof(INT)通常等于sizeof(长)== 4.作为一项规则拇指, INT 是处理器能以最快的工作类型。无例外无规律...

编辑:删除了第二条规则,的sizeof(短)LT;的sizeof(长),这是不是C标准的一部分。在一些平台上,的sizeof(短)可能实际上是等于的sizeof(长)

Why is it that I'm finding the size of int and long int are shown to be 4 bytes? Is it that the int is by default long int?

解决方案

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

That's all you can count on. The rest is completely up to the implementation. In the olden days of DOS, 16 bit compilers usually has sizeof(int) == sizeof(short) == 2. On 32 bit systems, sizeof(int) is usually equal to sizeof(long) == 4. As a rule of thumb, int is the type the processor can work with the fastest. No rule without exceptions...

EDIT: Removed the second rule, sizeof(short) < sizeof(long), which is NOT part of the C standard. On some platforms, sizeof(short) may actually be equal to sizeof(long).

这篇关于是用C默认长整型诠释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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