c - 当我按位移位 1 << 45 时,怎么会得到一个大整数

标签 c bit-manipulation shift

为什么我得到这么大的整数?

int ans = 1 << 45;
printf("Check: %d", ans);
return 0;

查询:1858443624

最佳答案

这是 C 中的未定义行为。任何事情都可能发生,包括处理器异常或程序其他部分的不可预测的更改(这可能是积极的编译器优化的副作用)。

6.5.7/3 [...] If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.

Source

关于c - 当我按位移位 1 << 45 时,怎么会得到一个大整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12221819/

相关文章:

javascript - 如何对纯二进制数据进行纯按位运算

java - long 的 Java 按位表示会有所不同吗?

java - 如何将这个二进制乘法代码的答案转化为二进制?

visual-studio - Visual Studio中的IntelliJ Shift Shift快捷方式(全局搜索)

c - 'memcpy'(合并两个结构)

c - 如何在 C 中检索传递给 linux 系统调用的参数?

c - 为什么这个函数会输出它所做的数字?

c - 修改C中for循环的表示

c - unsigned char 的最大值

r - 如何添加具有 NA 的行作为 R 中的先前列?