I am writing a program in C to calculate the range of different data types. Please look at the following code:
#include <stdio.h>
main()
{
    int a;
    long b;
    for (a = 0; a <= 0; --a)
        ;
    ++a;
    printf("INT_MIN: %d\n", a);
    for (a = 0; a >= 0; ++a)
        ;
    --a;
    printf("INT_MAX: %d\n", a);
    for (b = 0; b <= 0; --b)
        ;
    ++b;
    printf("LONG_MIN: %d\n", b);
    for (b = 0; b >= 0; ++b)
        ;
    --b;
    printf("LONG_MAX: %d\n", b);
}
The output was:
INT_MIN: -32768
INT_MIN: 32767
LONG_MIN: 0
LONT_MAX: -1
The program took a long pause to print the long values. I also put a printf inside the third loop to test the program (not mentioned here). I found that b did not exit the loop even when it became positive.
I used the same method of calculation. Why did it work for int but not for long?
 
     
     
     
     
    