[英]About integer promotion in C, short
void main(){
char c;
unsigned char uc;
unsigned short us1, us2;
short s1, s2;
c = 0xf0; uc = 0xf0;
us1 = c; us2 = uc;
printf("us1 = %x, \t us2 = %x\n", us1, us2);
s1 = c; s2 = uc;
printf("s1 = %x, \t s2 = %x\n", s1, s2);
}
結果:us1 = fff0,us2 = f0 s1 = fffffff0,s2 = f0
為什么s1是這樣的? 即使在32位且short的大小為2個字節
這是因為在對printf()
的變量參數調用中, short
被提升為int
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.