SoFunction
Updated on 2025-03-10

Solution to find the maximum value of unsigned int and the maximum value of int on a 32-bit machine

Copy the codeThe code is as follows:

#include <>
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);
}

Copy the codeThe code is as follows:

#include <>
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);
}

After gcc is compiled:
int_sizeof1.c: In function 'main':
int_sizeof1.c:5: Warning: integer overflow
After running:
The max value of int on 32 machine: 4294967295
 
After VC6.0 and java are compiled, there are no errors.
After running:
The max value of int on 32 machine: 4294967295
Copy the codeThe code is as follows:

#include <>
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 for writing its int into a signed type is as follows:
Copy the codeThe code is as follows:

#include <>
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);
}

After gcc is compiled:
int_sizeof1.c: In function 'main':
int_sizeof1.c:5: Warning: integer overflow
After running:
The max value of int on 32 machine: 2147483647
After VC6.0 and java are compiled, there are no errors.
After running:
The max value of int on 32 machine: 2147483647
Because the highest bit of int is the sign bit.