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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于C中的整数提升,简称相关的知识,希望对你有一定的参考价值。

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, 	 us2 = %x
", us1, us2);
    s1 = c; s2 = uc;
    printf("s1 = %x, 	 s2 = %x
", s1, s2);
}

结果:us1 = fff0,us2 = f0 s1 = fffffff0,s2 = f0

s1为什么会这样?即使在32位和sizeof short是2个字节

答案

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

以上是关于关于C中的整数提升,简称的主要内容,如果未能解决你的问题,请参考以下文章