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个字节

最佳答案

这是因为在对short的变量参数调用中,int被提升为printf()

09-28 08:55