c-programming

Simple C programs
git clone git://git.laack.co/c-programming.git
Log | Files | Refs

max-int-size.c (1154B)


      1 #include <stdio.h>
      2 
      3 // This weirdness is why you might use stdint
      4 // size(long long) == size(long) is weird
      5 
      6 int printSigned(){
      7     signed int current, prior;
      8     
      9     prior = 0;
     10     current = 1;
     11 
     12     while(current > prior){
     13         prior = current;
     14         current += 1;
     15     }
     16 
     17     printf("Signed: %d to ", current);
     18     printf("%d\n", prior);
     19     return 0;
     20 }
     21 int printUnsigned(){
     22 
     23     unsigned int prior = 0;
     24     unsigned int current = 1;
     25 
     26     while(current > prior){
     27         prior = current;
     28         current += 1;
     29     }
     30 
     31     printf("Unsigned: %u to ", current);
     32     printf("%u\n", prior);
     33     return 0;
     34 }
     35 
     36 
     37 int main(){
     38     printSigned();
     39     printUnsigned();
     40     int nt;
     41     float ft;
     42     double db;
     43     short sh;
     44     long ln;
     45     long long int lnln;
     46     long double lndb;
     47     printf("Int size is %u bytes\n", sizeof(nt));
     48     printf("Float size is %u bytes\n", sizeof(ft));
     49     printf("Double size is %u bytes\n", sizeof(db));
     50     printf("Short size is %u bytes\n", sizeof(sh));
     51     printf("Long size is %u bytes\n", sizeof(ln));
     52     printf("Long Long size is %u bytes\n", sizeof(lnln));
     53     printf("Long Double size is %u bytes\n", sizeof(lndb));
     54 }