#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned int max_int = 0-1;
printf("The max value of unsigned int on 32 machine: %u/n", max_int);
}
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned int max_int = 0-1;
printf("The max value of unsigned int on 32 machine: %u/n", max_int);
}
gcc編譯后:
int_sizeof1.c: 在函數(shù)‘main'中:
int_sizeof1.c:5: 警告:整數(shù)溢出
運(yùn)行后:
The max value of int on 32 machine: 4294967295
VC6.0和java編譯后,無錯(cuò)誤。
運(yùn)行后:
The max value of int on 32 machine: 4294967295
#include <stdio.h>
int main(int argc, char *argv[])
{
int max_int = (1<<31)-1;
printf("The max value of int on 32 machine: %d/n", max_int);
}
將其int寫成有符號(hào)型的程序如下:
#include <stdio.h>
int main(int argc, char *argv[])
{
int max_int = (1<<31)-1;
printf("The max value of int on 32 machine: %d/n", max_int);
}
gcc編譯后:
int_sizeof1.c: 在函數(shù)‘main'中:
int_sizeof1.c:5: 警告:整數(shù)溢出
運(yùn)行后:
The max value of int on 32 machine: 2147483647
VC6.0和java編譯后,無錯(cuò)誤。
運(yùn)行后:
The max value of int on 32 machine: 2147483647
因?yàn)閕nt的最高位是符號(hào)位。