int 类型Type int

带符号或无符号的 int 项的大小是特定计算机上的一个整数的标准大小。The size of a signed or unsigned int item is the standard size of an integer on a particular machine. 例如,在 16 位操作系统中,int 类型通常是 16 位(或 2 字节)。For example, in 16-bit operating systems, the int type is usually 16 bits, or 2 bytes. 在 32 位操作系统中,int 类型通常是 32 位(或 4 字节)。In 32-bit operating systems, the int type is usually 32 bits, or 4 bytes. 因此,int 类型与 short int 或 long int 类型等效,unsigned int 类型与 unsigned short 或 unsigned long 类型等效,具体取决于目标环境。Thus, the int type is equivalent to either the short int or the long int type, and the unsigned int type is equivalent to either the unsigned short or the unsigned long type, depending on the target environment. 除非另有规定,否则所有 int 类型都表示带符号值。The int types all represent signed values unless specified otherwise.

类型说明符 intunsigned int(或简写为 unsigned)定义 C 语言的某些功能(例如,enum 类型)。The type specifiers int and unsigned int (or simply unsigned) define certain features of the C language (for instance, the enum type). 在这些情况下,int 的定义和特定实现的 unsigned int 决定实际存储。In these cases, the definitions of int and unsigned int for a particular implementation determine the actual storage.

Microsoft 专用Microsoft Specific

带符号整数以 2 的补数的形式表示。Signed integers are represented in two's-complement form. 最高有效位保存符号:1 表示负数,0 表示整数或零。The most-significant bit holds the sign: 1 for negative, 0 for positive and zero. 值的范围在 C++ 整数限制中给定(摘自 LIMITS.H 头文件)。The range of values is given in C++ Integer Limits, which is taken from the LIMITS.H header file.

结束 Microsoft 专用END Microsoft Specific

备注

int 和 unsigned int 类型说明符在 C 程序中的使用很广泛,因为这些类型允许特定计算机以对自己最有效的方式处理整数值。The int and unsigned int type specifiers are widely used in C programs because they allow a particular machine to handle integer values in the most efficient way for that machine. 但是,由于 int 和 unsigned int 类型的大小不同,依赖于特定 int 大小的程序不能移植到其他计算机。However, since the sizes of the int and unsigned int types vary, programs that depend on a specific int size may not be portable to other machines. 若要使程序更易于移植,则可以使用带 sizeof 运算符(如 sizeof 运算符中所讨论的)的表达式,而不是具有硬编码数据大小的表达式。To make programs more portable, you can use expressions with the sizeof operator (as discussed in The sizeof Operator) instead of hard-coded data sizes.

请参阅See Also

基本类型的存储Storage of Basic Types