memory - Why can I go up to this number with an integer? -


i learning c , read in kernighan&ritchie's book integers int included in set specific set [-32767;32767]. tried verify assertion writing following program increment variable count 1 limit before fall in negative numbers.

#include <stdio.h>  int main(void){     int count = 1;     while(count > 0){         count++;         printf("%d\n", count);     }      return 0; } 

and surprisingly got output:

1 ...... 2147483640 2147483641 2147483642 2147483643 2147483644 2147483645 2147483646 2147483647 -> lot more 32767?! -2147483648  

i not understand, why output? , doubt m. ritchie made mistake ;)

you're on 32- or 64-bit machine , c compiler using has 32-bit integers. in 2's complement binary, highest positive integer 31 bites, or 2^31-1 or 2147483647, observing.

note doesn't violate k&r's claim integer value includes range [-32768;32767].