是C中的大小; INT" 2字节或4字节? [英] Is the size of C "int" 2 bytes or 4 bytes?

查看:200
本文介绍了是C中的大小; INT" 2字节或4字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问C中的整型变量占用2个字节或4个字节?哪些因素,这取决于?

Does an Integer variable in C occupy 2 bytes or 4 bytes? What are the factors that it depends on?

大多数的教科书都说整数变量占用2个字节。
但是,当我运行一个程序打印整数数组的连续地址就显示4的区别。

Most of the textbooks say integer variables occupy 2 bytes. But when I run a program printing the successive addresses of an array of integers it shows the difference of 4.

推荐答案

我知道这是等于的sizeof(INT)。的大小 INT 真的是编译器相关的。早在一天,当处理器是16位,一个 INT 为2个字节。现今,这是最常见的是32位的系统上的4个字节或64比特的系统的8个字节。

I know it's equal to sizeof(int). The size of an int is really compiler dependent. Back in the day, when processors were 16 bit, an int was 2 bytes. Nowadays, it's most often 4 bytes on a 32 bits system or 8 bytes on 64 bits system.

不过,使用的sizeof(INT),是为执行该程序的特定系统的整数大小的最佳方式。

Still, using sizeof(int) is the best way to get the size of an integer for the specific system the program is executed on.

这篇关于是C中的大小; INT" 2字节或4字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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