关于C中的整数提升,简称

时间:2014-07-02 06:31:12

标签: c integer

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

1 个答案:

答案 0 :(得分:0)

这是因为shortint的变量参数调用中被提升为printf()