c语言unsigned int和int

```c

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

void main(){

    int a=-1;

    unsigned int b = -1;

    printf("%d\n",a);

    printf("%u\n",b);

    // <<符合运算优先级大于-

    printf("%u\n",(1<<32)-1); //32位全为1,为unsigned int类型的最大值,为int类型的-1

    printf("%d\n",(1<<32)-1);

    printf("%d\n",sizeof(int));

    printf("%d\n",sizeof(long));

    printf("%d\n",sizeof(long long));

    // 正数原码反码补码相同;负数反码等于原码除符号位以外全部取反,补码等于反码加一

    /*输出结果:

        -1

        4294967295

        4294967295

        -1

        4

        4

        8

    */

}

```

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章