被肉体混淆10,然后除以10
get confused by mutlibly by 10 and then divide by 10
本文关键字:然后 更新时间:2023-10-16
我有点困惑,因为当我将int变量乘以10,然后将其除以10,我认为变量值不应该更改,但我得到了不同的结果,我缺少或我应该知道的东西这是代码
#include <iostream>
using namespace std;
int main()
{
int intVar = 1500000000; //1,500,000,000
intVar = (intVar * 10) / 10; //result too large
cout << “intVar = “ << intVar << endl; //wrong answer
return 0 ;
}
任何帮助解释,请
32位int
的范围是-(1 << 32)
到(1 << 32) - 1
。
当15亿次乘以10时,它超过了int
的上限(约为21亿),并溢出到其他数字,当该数字除以10,您将获得[新]数字的结果除以十。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- boost::asio如何生成多个协同程序,然后加入它们
- 如何将图像传输到c++(dll)中的缓冲区,然后在c#的缓冲区中读/写
- 在std::thread中,joinable()然后join()线程安全吗
- C++:如何读取分离变量,然后读取向量
- 为什么我的递归函数按降序打印,然后按升序打印?
- 等待整个 omp 块完成,然后再调用第二个函数
- CMake:如何将库 A 链接到库 B,然后将可执行文件链接到库 A
- 如何存储用户输入的所有数据,然后在他们想要查看所有数据时显示它们
- '{'标记之前的预期类名,然后在预声明时无效使用不完整的类型'class class_name'
- 如何使变量从 x 到 y,然后从 y 返回到 x 并始终重复该过程
- 我有一个数组,我想输入一个范围,然后找到范围内所有偶数的总和?
- 如何正确地推回然后遍历堆中对象的向量?
- 我似乎无法为指针分配一个数组,然后更改数组的内容
- 如何在字符串中找到字符,然后在C++中提取其余的字符串
- 首先按给定顺序打印所有数字,然后使用 Array 打印所有字符和其他符号
- 将加密消息从 php 发送到 C++ 应用程序,然后使用 CryptoPP 进行解密
- 如何为 std::vector 分配内存,然后稍后为某些元素调用构造函数?