I'm trying to find out the ranges of different data types through direct computation........this is what I did.......
Code:
#include <stdio.h>
main()
{
char ch;
signed short sh;
signed int in;
signed long lo;
unsigned short ush;
unsigned int uin;
unsigned long ulo;
ch = sh = in = lo = ush = uin = ulo = 0;
printf("Ranges through computation:\n\n");
while (ch < (ch+1))
ch++;
printf("The range of a char is from %d to %d\n", ch+1, ch);
while (sh < (sh+1))
sh++;
printf("The range of a short is from %d to %d\n", sh+1, sh);
while (in < (in+1))
in++;
printf("The range of an int is from %d to %d\n", in+1, in);
while (lo < (lo+1))
++lo;
printf("The range of a long is from %ld to %ld\n", lo+1, lo);
while (ush < (ush+1))
++ush;
printf("The range of an unsigned short is from %u to %u\n", ush+1, ush);
while (uin < (uin+1))
++uin;
printf("The range of an unsigned int is from %u to %u\n", uin+1, uin);
while (ulo < (ulo+1))
++ulo;
printf("The range of an unsigned long is from %lu to %lu\n", ulo+1, ulo);
return 0;
}
The ranges of all data types in the program print correctly, except for the char type (the corresponding code is red) in which the loop continues for ever ........why is it so?
Thanks.
PS: The program only works when the code in red is deleted