註冊 登錄
Android 台灣中文網 返回首頁

jianrupan的個人空間 https://apk.tw/?1180935 [收藏] [複製] [分享] [RSS]

日誌

簡單的 int 與 unsigned int 的 運算概念

已有 225 次閱讀2015-6-24 11:10 |個人分類:軟體應用


解出以下列印結果:
unsigned int a = 0;
unsigned int b = 1;
unsigned int c = -1;
unsigned int d = 4294967295;
unsigned int e = 4294967294;
unsigned int f = 0;
f = a-b;
printf( "a-b = %d ", f );
printf( "c = %d ", c );
f = a-d;
printf( "a-d = %d ", f );
f = b-d;
printf( "b-d = %d ", f );
printf( "d = %d ", d );
f = d+1;
printf( "d+1 = %d ", f );
f = d-1;
printf( "d-1 = %d ", f );
printf( "e = %d ", e );
f = e-d;
printf( "e-d = %d ", f );
f = d-e;
printf( "d-e = %d ", f );



~~~~~~~~~~~
解出來了嗎?
讓我們看一下正確答案:
a-b = -1
c = -1
a-d = 1
b-d = 2
d = -1
d+1 = 0
d-1 = -2
e = -2
e-d = -1
d-e = 1

註記:
 int               範圍     -2,147,483,648 ~ 2,147,483,647
unsigned int 範圍                           0 ~ 4,294,967,295





路過

雞蛋

鮮花

握手

雷人

評論 (0 個評論)

facelist

您需要登錄後才可以評論 登錄 | 註冊