#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int a = ~0 >> 1;
cout << a << endl;
}
输出结果: -1;
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int a = (-2)>> 1;
cout << a << endl;
}
输出结果:-1;
采用的编译器为Microsoft Visual C++ 2013,默认逻辑右移。
rep(i, 5) dist[i] = 0x7fffffff;
dist<span style="white-space:pre"> </span>0x00f5ffb8{2147483647, 2147483647, 2147483647, 2147483647, 2147483647, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...}<span style="white-space:pre"> </span>int[105]</

这篇博客探讨了在C++中如何表示无穷大,特别提到了使用Microsoft Visual C++ 2013时逻辑右移操作的结果。作者发现,通过#define定义无穷大时,结果与预期不同,特别是在涉及字符串填充的情况下,导致dis数组的值变为-1,引发思考。
最低0.47元/天 解锁文章
3944

被折叠的 条评论
为什么被折叠?



