User Tools

Site Tools


haas:fall2022:common:datatyperanges

C/C++ Data Types and Ranges

1
#include <stdio.h>
 
int main()
{
    // Variable declarations
    //
    signed   char sc = 0;
    unsigned char uc = 0;    
 
    // Find the max value for a signed char (half of the max of an unsigned char)
    //
    sc = ((unsigned char)(uc-1)/2) + 1;
 
    fprintf(stdout, "TYPE: unsigned char\n-------------------\n");
    fprintf(stdout, "\tsize: %hhu bytes\n", sizeof(unsigned char));
    fprintf(stdout, "\t low: %hhu\n", uc);
    fprintf(stdout, "\thigh: %hhu\n", (uc-1)); // max of unsigned is 1 less than 0-- roll-over
    fprintf(stdout, "-------------------\n\n");
 
    fprintf(stdout, "TYPE:   signed char\n-------------------\n");
    fprintf(stdout, "\tsize: %hhu bytes\n", sizeof(signed char));
    fprintf(stdout, "\t low: %hhd\n", (sc-1));
    fprintf(stdout, "\thigh: %hhd\n", sc);
    fprintf(stdout, "-------------------\n\n");
 
    return(0);
}
haas/fall2022/common/datatyperanges.txt · Last modified: 2013/02/22 16:14 by 127.0.0.1