*}
codea teams

Size Of Data Types



Get the sizes of data types for your particular OS

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int verbose = 0;

int main(int argc, char *argv[])
{
    int c;
    extern char *optarg;
    extern int optind, optopt, opterr;

    while ((c = getopt(argc, argv, "v")) != -1) 
    {
        switch(c) 
        {
        case 'v':
            verbose = 1;
            break;
        case '?':
            printf("unknown arg %c\n", optopt);
            exit(-1);
            break;
        }
    }

    if (verbose)
    {
        printf("Char:   %d\n", sizeof(char));
        printf("Short:  %d\n", sizeof(short));
        printf("Int:    %d\n", sizeof(int));
        printf("Long:   %d\n", sizeof(long));
        printf("Long Long: %d\n", sizeof(long long));
        printf("Float:  %d\n", sizeof(float));
        printf("Double: %d\n", sizeof(double));
        printf("Long Double: %d\n", sizeof(long double));
        
    }
    else
    {
        printf("%d %d %d %d %d %d %d %d\n", sizeof(char), sizeof(short),
            sizeof(int), sizeof(long), sizeof(long long), sizeof (float), sizeof(double), sizeof(long double) );
    }
}