請參閱下面的簡單代碼:無符號長與負值
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
unsigned long currentTrafficTypeValueDec;
long input;
input=63;
currentTrafficTypeValueDec = (unsigned long) 1LL << input;
cout << currentTrafficTypeValueDec << endl;
printf("%u \n", currentTrafficTypeValueDec);
printf("%ld \n", currentTrafficTypeValueDec);
return 0;
}
爲什麼printf()的顯示currentTrafficTypeValueDec(無符號長)與負值?
輸出是:
9223372036854775808
0
-9223372036854775808
有趣的方式:) – Tim 2010-03-16 17:39:24