标签:溢出 pre std 语言 short class 不包含 情况 int
int x = 16; printf("%d\n", x >> 1);
10000, 不读最后一位, 输出 1000, 即为8;int x = 16; printf("%d\n", x << 1);
先将x转成二进制 10000, 往最后再读取一位(0, 或根据是否已经有移位), 输出 100000, 即为32;
#include <stdio.h>
int main()
{
int x = 16;
printf("%d\n", x >> 3);
printf("%d\n", x >> 2);
printf("%d\n", x >> 1);
printf("%d\n", x << 3);
printf("%d\n", x << 2);
printf("%d\n", x << 1);
}
结果为
2
4
8
128
64
32
标签:溢出 pre std 语言 short class 不包含 情况 int
原文地址:https://www.cnblogs.com/huangyuechujiu/p/12750798.html