0x7fffffff与0x3f3f3f3f

0x7fffffff和0x3f3f3f3f都是十六进制的数,0x7fffffff表示的是32字节的最大值,而0x3f3f3f3f的两倍还不如前者大,但某些时候后者比前者好用,比如与另一个数相加,这时结果会溢出,变为负数。所以说最大的不一定是最好的。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const int INF1=0x7fffffff;
const int INF2=0x3f3f3f3f;
int main()
{
    printf("%d %d\n",INF1,INF2);
    printf("%d\n",2*INF2);
    return 0;
}

测试结果如下:

 

猜你喜欢

转载自blog.csdn.net/qq_41410799/article/details/81408584