我是一个绝对的C初学者,正在尝试学习位移位。我写了一个小程序,通过右移测试除法。
代码如下:
#include<stdio.h>
int shift_divide_by_16(int x);
int main() {
int x = 32;
int y = shift_divide_by_16(x);
printf("%d\n", y);
return 0;
}
int shift_divide_by_16(int x) {
x >> 4;
printf("%d\n", x);
return x;
}
该程序打印32 32
。为什么不打印2 2
?
谢谢。
发布于 2014-09-01 03:54:57
您需要将值重新赋值给x
x = x >> 4
发布于 2014-09-01 03:58:52
您还可以使用:
x >>= 4;
https://stackoverflow.com/questions/25595711
复制相似问题