C ++中的长整数溢出 [英] Long integer overflow in C++
本文介绍了C ++中的长整数溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么下面的代码给出整数溢出警告:
Why the below code gives integer overflow warning:
#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;
两个 int 相乘.试试
long long int x = 100000LL * 99999;
这篇关于C ++中的长整数溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文