N
Nicholas Zhou
Hi,
I was writing a testing program to test the ranges of char, short, int
and long variables on my computer, both signed and unsigned.
Everything was fine except for unsigned int and unsigned long. I got
0 to -1 for both. The expected answers should be:
unsigned int: 0 to 65535
unsigned long: 0 to 4294967295
What might be wrong here? Please help.
Here is the program I wrote:
-------------------
#include <stdio.h>
#include <limits.h>
int main(void)
{
printf("Unsigned char: %d\t%d\n", 0, UCHAR_MAX);
printf("Signed char: %d\t%d\n", SCHAR_MIN, SCHAR_MAX);
printf("Unsigned short: %d\t%d\n", 0, USHRT_MAX);
printf("(Signed) short: %d\t%d\n", SHRT_MIN, SHRT_MAX);
printf("Unsigned int: %d\t%d\n", 0, UINT_MAX);
printf("(Signed) int: %d\t%d\n", INT_MIN, INT_MAX);
printf("Unsigned long: %d\t%d\n", 0, ULONG_MAX);
printf("(Signed) long: %d\t%d\n", LONG_MIN, LONG_MAX);
getchar();
return 0;
}
-----------------
I was writing a testing program to test the ranges of char, short, int
and long variables on my computer, both signed and unsigned.
Everything was fine except for unsigned int and unsigned long. I got
0 to -1 for both. The expected answers should be:
unsigned int: 0 to 65535
unsigned long: 0 to 4294967295
What might be wrong here? Please help.
Here is the program I wrote:
-------------------
#include <stdio.h>
#include <limits.h>
int main(void)
{
printf("Unsigned char: %d\t%d\n", 0, UCHAR_MAX);
printf("Signed char: %d\t%d\n", SCHAR_MIN, SCHAR_MAX);
printf("Unsigned short: %d\t%d\n", 0, USHRT_MAX);
printf("(Signed) short: %d\t%d\n", SHRT_MIN, SHRT_MAX);
printf("Unsigned int: %d\t%d\n", 0, UINT_MAX);
printf("(Signed) int: %d\t%d\n", INT_MIN, INT_MAX);
printf("Unsigned long: %d\t%d\n", 0, ULONG_MAX);
printf("(Signed) long: %d\t%d\n", LONG_MIN, LONG_MAX);
getchar();
return 0;
}
-----------------