======Project: Data Types====== A project for CSCS 2330 by Paul Sechrist during the Spring 2013. =====Objectives===== Play with data type size example, experiment with it a little. =====Code===== #include #include int main() { /* Data Types Size %hhd Signed char 1 %hhu unsigned char 1 %hd signed short int 2 %hu unsigned short int 2 %d signed int 4 %u unsigned int 4 %ld signed long int 8 %lu unsigned long int 8 %llu signed long long int 8 %llu unsigned long long int 8 %f float 0 %lf double 0 %llf long double 0 */ signed char sc=0; unsigned char uc=0; signed short int ssi=0; unsigned short int usi=0; signed int si=0; unsigned int ui=0; signed long int sli=0; unsigned long int uli=0; signed long long int slli=0; unsigned long long int ulli=0; float f=0; double d=0; long double ld=0; fprintf(stdout, "a signed char is %hhu bytes \n", sizeof(sc)); fprintf(stdout, "lower bound is: %hhd\n", ((unsigned char)(sc-1)/2)+1); fprintf(stdout, "upper bound is: %hhd \n", ((unsigned char)(sc-1)/2)); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "an unsigned char is %hhu bytes\n", sizeof(uc)); fprintf(stdout, "lower bound is: %hhu\n", uc); fprintf(stdout, "upper bound is: %hhu\n", uc-1); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "a signed short int is %hd bytes \n", sizeof(ssi)); fprintf(stdout, "lower bound is: %hd\n", ((unsigned short int)(ssi-1)/2)+1); fprintf(stdout, "upper bound is: %hd \n", ((unsigned short int)(ssi-1)/2)); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "an unsigned short int is %hu bytes\n", sizeof(usi)); fprintf(stdout, "lower bound is: %hu\n", usi); fprintf(stdout, "upper bound is: %hu\n", usi-1); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "a signed int is %d bytes \n", sizeof(si)); fprintf(stdout, "lower bound is: %d\n", ((unsigned int)(si-1)/2)+1); fprintf(stdout, "upper bound is: %d \n", ((unsigned int)(si-1)/2)); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "an unsigned int is %u bytes\n", sizeof(ui)); fprintf(stdout, "lower bound is: %u\n", ui); fprintf(stdout, "upper bound is: %u\n", ui-1); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "a signed long int is %ld bytes \n", sizeof(sli)); fprintf(stdout, "lower bound is: %ld\n", ((unsigned long int)(sli-1)/2)+1); fprintf(stdout, "upper bound is: %ld \n", ((unsigned long int)(sli-1)/2)); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "an unsigned long int is %lu bytes\n", sizeof(uli)); fprintf(stdout, "lower bound is: %lu\n", uli); fprintf(stdout, "upper bound is: %lu\n", uli-1); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "a signed long long int is %lld bytes \n", sizeof(slli)); fprintf(stdout, "lower bound is: %lld\n", ((unsigned long long int)(slli-1)/2)+1); fprintf(stdout, "upper bound is: %lld \n", ((unsigned long long int)(slli-1)/2)); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "an unsigned long long int is %llu bytes\n", sizeof(ulli)); fprintf(stdout, "lower bound is: %llu\n", ulli); fprintf(stdout, "upper bound is: %llu\n", ulli-1); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "a float is %f bytes \n", sizeof(f)); fprintf(stdout, "lower bound is: %f\n", ((float)(f-1)/2)+1); fprintf(stdout, "upper bound is: %f \n", ((float)(f-1)/2)); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "an double is %lf bytes\n", sizeof(d)); fprintf(stdout, "lower bound is: %lf\n", d); fprintf(stdout, "upper bound is: %lf\n", d-1); fprintf(stdout, "----------------------------\n"); fprintf(stdout, "a long double is %llf bytes \n", sizeof(ld)); fprintf(stdout, "lower bound is: %llf\n", ((long double)(ld-1)/2)+1); fprintf(stdout, "upper bound is: %llf\n", ((long double)(ld-1)/2)); fprintf(stdout, "----------------------------\n"); return(0); } ====Execution==== lab46:~/src/datastructures/review$ ./fun a signed char is 1 bytes lower bound is: -128 upper bound is: 127 ---------------------------- an unsigned char is 1 bytes lower bound is: 0 upper bound is: 255 ---------------------------- a signed short int is 2 bytes lower bound is: -32768 upper bound is: 32767 ---------------------------- an unsigned short int is 2 bytes lower bound is: 0 upper bound is: 65535 ---------------------------- a signed int is 4 bytes lower bound is: -2147483648 upper bound is: 2147483647 ---------------------------- an unsigned int is 4 bytes lower bound is: 0 upper bound is: 4294967295 ---------------------------- a signed long int is 8 bytes lower bound is: -9223372036854775808 upper bound is: 9223372036854775807 ---------------------------- an unsigned long int is 8 bytes lower bound is: 0 upper bound is: 18446744073709551615 ---------------------------- a signed long long int is 8 bytes lower bound is: -9223372036854775808 upper bound is: 9223372036854775807 ---------------------------- an unsigned long long int is 8 bytes lower bound is: 0 upper bound is: 18446744073709551615 ---------------------------- a float is 0.000000 bytes lower bound is: 0.500000 upper bound is: -0.500000 ---------------------------- an double is 0.000000 bytes lower bound is: 0.000000 upper bound is: -1.000000 ---------------------------- a long double is 0.000000 bytes lower bound is: 0.500000 upper bound is: -0.500000 ---------------------------- lab46:~/src/datastructures/review$ =====Reflection===== Good way to review data types and C in general. =====References===== Matt's examples.