View Single Post
Old 24-08-2013, 06:15 PM   #1
Mighty Midget
Pox Vobiscum
 
Mighty Midget's Avatar


 
Join Date: Mar 2006
Location: Krakeroy, Norway
Posts: 3,014
Default C code noob's corner

I am (trying???) to learn C as part of my studies. Things are going fairly ok in programming but extending one task is giving me some grey hairs.

This code will output the size in bytes for various types of variables, as well as the value range. However, things are tricky when it comes to the
float
double
both signed and unsigned, long and short, if it's there, I want to include it in the program.

Code:
#include <stdio.h>
#include <limits.h>
#include <float.h>

int main()
{
    printf("char... \tsize: %d byte \t", sizeof(char));
    printf("%d to %d \n", CHAR_MIN, CHAR_MAX);
    printf("unsgn char... \tsize: %d byte \t", sizeof(unsigned char));
    printf("0 to %d \n", UCHAR_MAX);
    printf("short int... \tsize: %d bytes \t", sizeof(short int));
    printf("%d to %d \n", SHRT_MIN, SHRT_MAX);
    printf("unsgn s int... \tsize: %d bytes \t", sizeof(unsigned short int));
    printf("0 to %d \n", USHRT_MAX);
    printf("long int... \tsize: %d bytes \t", sizeof(long int));
    printf("%ld to %ld \n", LONG_MIN, LONG_MAX);
    printf("unsgn l int... \tsize: %d bytes \t", sizeof(unsigned long int));
    printf("0 to %u \n", ULONG_MAX);                                            
    printf("float... \tsize: %d bytes \n", sizeof(float));
    printf("double... \tsize: %d bytes \n)", sizeof(double));
return 0;
}
As you can see, the MIN and MAX are missing for the last two, the float and double, and I haven't figured out if there are any long/short/signed/unsigned versions of these two.

The float header was included as I messed around with different float constants not getting anywhere.

Any input, so to speak, would be greatly appreciated!
__________________
Je Suis Charlie
Mighty Midget is offline                         Send a private message to Mighty Midget
Reply With Quote