Originally Posted by
alx2progrmz
Hi, I'm trying to see what is the max limit of unsigned int. I get the size of int of 4 bytes. But the UINT_MAX is giving me -1.
What am I doing wrong?
Several things.
1) Turn on and turn up your warning level to the highest setting!
2) See my comments in the corrected code below:
Code:
#include <stdio.h>
#include <limits.h>
int main(void)
{
// sizeof() returns a size_t not int!
size_t i = sizeof(int);
// The proper format specifier for a size_t is "%zu".
printf("The size of int is %zu\n", i);
// You terminate the line with a colon NOT a semi-colon!
printf("The max limit of unsigned is %u\n", UINT_MAX);
return 0;
}