c語言中經常忽略的型別提公升

2021-06-09 14:03:05 字數 393 閱讀 2595

型別提公升常發生在表示式中,char,short(包括它們的signed和unsigned型別)以及列舉型別enum,在表示式中被提公升為int(如果int足夠表示轉換後的數的話,否則就是unsigned int);在含有unsigned int的表示式裡,int轉換為unsigned int來做運算。低階向高階發生轉換。

例如:1:『a'+1=98;

2:sizeof 'a'=?,注意:結果不是1,是4,這是因為字元發生了型別提公升。sizeof是關鍵字,也是表達是運算

3: if(-1

printf("yes");

else 

printf("error");

結果是「error";sizeof的結果為unsigned型別,int發生型別提公升,-1變為非常大的乙個數。

Python 語言中經常有疑惑的地方

可以這樣,不用儲存遞迴中的變數 import os def findfile str,dir os.path.abspath for x in os.listdir dir if os.path.isdir os.path.join dir,x findfile str,os.path.join d...

Python 語言中經常有疑惑的地方

可以這樣,不用儲存遞迴中的變數 import os def findfile str,dir os.path.abspath for x in os.listdir dir if os.path.isdir os.path.join dir,x findfile str,os.path.join d...

C語言裡的型別提公升

一 型別的提公升 把char unsigned char short unsigned short轉換成int型別稱為型別提公升 promotion 1.如果short的位元組長度小於int的位元組長度 char轉換成 int unsigned char轉換成 int short轉換成 int un...