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位且sizeof short是2bytes
答案 0 :(得分:0)
这是因为short
在int
的变量参数调用中被提升为printf()
。