阅读:52,895C语言支持 5 种带符号的整数类型。其中大多数整数类型具有多个同义词,见表1。
表1:带符号的标准整数类型
类型同义词
signed char
intsigned, signed int
shortshort int, signed short, signed short int
longlong int, signed long, signed long int
long long (C99)long long int, signed long long,signed long long int
对于表1列出来的 5 种带符号整数类型,它们每个都有对应的无符号类型。与带符号类型相比,对应的无符号类型内存大小相同,对齐方式(alignment)也相同。换句话说,如果编译器将 signed int 对象对齐到偶数地址上,则unsigned int 对象也对齐到偶数地址。表2列出了无符号类型。
表2:无符号的标准整数类型
类型同义词
_Boolbool(在stdbool.h 头文件中定义)
unsigned char
unsigned intunsigned
unsigned shortunsigned short int
unsigned longunsigned long int
unsigned long longunsigned long long int
C99 引入了无符号整数类型 _Bool 用来表示布尔值。