大数的乘法产生错误的价值

时间:2018-06-02 21:05:10

标签: c++ integer-overflow long-long

我有代码

long long x = 200000 * 200000;
cout << x << endl;

输出1345294336 我尝试过转换为字符串并输出每个数字,但它仍然输出相同的内容

1 个答案:

答案 0 :(得分:4)

尝试

long long x = 200000LL * 200000LL; 
std::cout << x << std::endl;

注意&#34; LL&#34;后缀。要详细了解如何使用数字文字的后缀,请访问Integer Literals上的cppreference.com页面。

相关问题