long int
long int即long,给人的感觉好像是长整型,但实际上,它和int一样,只有32位。cppreference给出的定义是——
int - basic integer type. The keyword int may be omitted if any of the modifiers listed below are used. If no length modifiers are present, it’s guaranteed to have a width of at least 16 bits. However, on 32/64 bit systems it is almost exclusively guaranteed to have width of at least 32 bits.
long - target type will have width of at least 32 bits.
在实际的使用中,long与int几乎没有区别
既然long int与int相同,那么为什么还有long int这种尴尬的类型呢?
原因是早期的C编译器定义了long int占用4个字节,int占用2个字节,long int是名副其实的长整型。在ANSI C的标准中,对长整型的定义也是long int应该至少和int一样长,而不是long int 一定要比int占用存储字节长。所以,正确的关系应该是——
long≥int≥short long\geq int\geq short
long≥int≥short
新版的C/C++标准兼容了早期的这一设定。
long long
long long则不同,long long是C++的64位整型的基本类型,“现任”长整型,从C99开始引入这个概念。
原文:https://blog.youkuaiyun.com/CV_Jason/article/details/85244813