Go Back   Forums > Community Chatterbox > Tech Corner
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


Similar Threads
Thread Thread Starter Forum Replies Last Post
EoF Corner Eagle of Fire Offers 6 03-02-2010 05:01 PM
The end of the file corner Eagle of Fire Music, Art, Movies 8 08-12-2009 12:09 AM
Spoonman's Art Corner Spoonman Music, Art, Movies 122 15-01-2009 09:35 PM
Spoonman's Music Corner Spoonman Music, Art, Movies 3 25-06-2005 05:18 PM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 04:44 AM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.