What#39;s the difference between long long and long(long long 和 long 和有什么不一样)
问题描述
long long 和 long 有什么区别?而且它们都不适用于 12 位数字 (600851475143),我是不是忘记了什么?
What's the difference between long long and long? And they both don't work with 12 digit numbers (600851475143), am I forgetting something?
#include <iostream>
using namespace std;
int main(){
long long a = 600851475143;
}
推荐答案
按照标准,保证的是:
int必须至少为 16 位long必须至少为 32 位long long必须至少为 64 位
intmust be at least 16 bitslongmust be at least 32 bitslong longmust be at least 64 bits
在主要的 32 位平台上:
On major 32-bit platforms:
int是 32 位long也是 32 位long long是 64 位
intis 32 bitslongis 32 bits as welllong longis 64 bits
在主要的 64 位平台上:
On major 64-bit platforms:
int是 32 位long是 32 位或 64 位long long也是 64 位
intis 32 bitslongis either 32 or 64 bitslong longis 64 bits as well
如果您需要特定应用程序的特定整数大小,而不是相信编译器会选择您想要的大小,#include <stdint.h>(或 <cstdint>) 所以你可以使用这些类型:
If you need a specific integer size for a particular application, rather than trusting the compiler to pick the size you want, #include <stdint.h> (or <cstdint>) so you can use these types:
int8_t和uint8_tint16_t和uint16_tint32_t和uint32_tint64_t和uint64_t
int8_tanduint8_tint16_tanduint16_tint32_tanduint32_tint64_tanduint64_t
您可能还对#include <stddef.h>(或<cstddef>)感兴趣:
You may also be interested in #include <stddef.h> (or <cstddef>):
size_tptrdiff_t
这篇关于long long 和 long 和有什么不一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:long long 和 long 和有什么不一样
基础教程推荐
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
