<分区>
为什么下面的代码给出整数溢出警告:
#include <stdio.h>
int main()
{
long long int x = 100000 * 99999;
return 0;
}
而下面的代码完美运行:
#include <stdio.h>
int main()
{
long long int x = 100000000000000;
return 0;
}
标签 c++
<分区>
为什么下面的代码给出整数溢出警告:
#include <stdio.h>
int main()
{
long long int x = 100000 * 99999;
return 0;
}
而下面的代码完美运行:
#include <stdio.h>
int main()
{
long long int x = 100000000000000;
return 0;
}
最佳答案
因为这里
long long int x = 100000 * 99999;
两个整数相乘。尝试
long long int x = 100000LL * 99999;
关于c++ - C++ 中的长整数溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874465/