fork download
  1. #include <stdio.h>
  2. #include <assert.h>
  3. // http://stackoverflow.com/a/37044707/1116364
  4.  
  5. unsigned long calculate_max_ulong(void) {
  6. unsigned long follow = 0;
  7. unsigned long lead = 1;
  8. while (lead != 0) {
  9. ++lead;
  10. ++follow;
  11. }
  12. return follow;
  13. }
  14.  
  15. int main(void) {
  16. assert(sizeof(long) == sizeof(unsigned long));
  17. unsigned long umax_h = calculate_max_ulong() / 2u;
  18. long max = umax_h;
  19. long min = - max - 1;
  20. printf("Range of long (%zu): %ld to %ld\n", sizeof(long), min, max);
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
Range of long (4): -2147483648 to 2147483647