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

    */

}

```

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