作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个程序如何产生以下输出?节目
#include<stdio.h>
int main()
{
printf("%x", -1<<1);
getchar();
return 0;
}
输出
fffffffe
最佳答案
C 中未定义负符号整数值的左移。
6.5.7 Bitwise shift operators
- The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled withzeros. If E1 has an unsigned type, the value of the result is E1 × 2 E2 , reduced moduloone more than the maximum value representable in the result type. If E1 has a signedtype and nonnegative value, and E1 × 2 E2 is representable in the result type, then that isthe resulting value; otherwise, the behavior is undefined.
在您的情况下,-1
的类型是signed int
。您看到的结果没有意义,而是架构的产物。
关于c - 它如何使输出 "fffffffe"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37599418/
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我是一名优秀的程序员,十分优秀!