To find the maximum value of unsigned int and the maximum value of int on a 32 bit machine
- 2020-04-02 01:03:24
- OfStack
#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);
}
The same code at the page code block index 0
GCC compiled:
Int_sizeof1.c: in the function 'main' :
Int_sizeof 1.c:5: warning: integer overflow
After the operation:
The Max value of int on 32 machine: 4294967295
VC6.0 and Java compiled, no errors.
After the operation:
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);
}
The program to write its int as a signed type is as follows:
The same code at the page code block index 2
GCC compiled:
Int_sizeof1.c: in the function 'main' :
Int_sizeof 1.c:5: warning: integer overflow
After the operation:
The Max value of int on 32 machine: 2147483647
VC6.0 and Java compiled, no errors.
After the operation:
The Max value of int on 32 machine: 2147483647
Because the highest bit of int is the sign bit.