我正在阅读 Stephan G. Kochan 着的《Programming in C》
。他说 C 只有五种数据类型; int
、float
、double
、char
和 _Bool
。
long
呢?它不是内置类型吗? http://www.programiz.com/c-programming/c-data-types说 long
是修改大小的限定符。如果它是一个限定符,那么它应该只用作一个long int
,而不是一个独立的long
。
_Bool
呢?网上很多教程都说C中没有boolean类型。
相关:
最佳答案
He states that C has only five data types; int, float, double, char and _Bool.
这过于简单化了。可能是故意的,如果这本书是针对初学者的。
如果您查看 C11 6.2.5,它会列出以下不同的数据类型:
字符类型 (6.2.5/15)
char
signed char
unsigned char
标准有符号整数类型 (6.2.5/4)
signed char
short int
int
long int
long long int
标准无符号整数类型 (6.2.5/5)
_Bool
unsigned char
unsigned short int
unsigned int
unsigned long int
unsigned long long int
真正的 float 类型 (6.2.5/10)
float
double
long double
复杂类型 (6.2.5/11)
float _Complex
double _Complex
long double _Complex
枚举类型 (6.2.5/16)
enum {}
void 类型 (6.2.5/19)(void 类型是不完整的类型)
void
派生类型 (6.2.5/20)
- 数组类型
- 结构类型
- union 类型
- 函数类型
- 指针类型
- 原子型
正式术语是类型说明符 6.7.2:
type-specifier:
void
char
short
int
long
float
double
signed
unsigned
_Bool
_Complex
atomic-type-specifier
struct-or-union-specifier
enum-specifier
typedef-name
At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.
— void
— char
— signed char
— unsigned char
— short, signed short, short int, or signed short int
— unsigned short, or unsigned short int
— int, signed, or signed int
— unsigned, or unsigned int
— long, signed long, long int, or signed long int
— unsigned long, or unsigned long int
— long long, signed long long, long long int, or signed long long int
— unsigned long long, or unsigned long long int
— float
— double
— long double
— _Bool
— float _Complex
— double _Complex
— long double _Complex
— atomic type specifier
— struct or union specifier
— enum specifier
— typedef name
正如我们所见,long
是一个类型说明符。它不是类型限定符。
关于c - long 是 C 中的数据类型还是限定符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37986813/