#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]
以上这种方法也是表示无穷大的一种。
很疑惑的是,如果用define加以定义,则会出现不一样的事情:
#define INF 0x7fffffff
#define mcv(a, v) memset(a, v, sizeof(a))
mcv(dis,0)
此时,dis数组的值为-1!
难道因为是用字符串填充的缘故?