#include <stdio.h>
#include <limits.h>
#include <float.h>
#define BITS_PER_BYTE 8
int
main(void)
{
int charBytes = sizeof(char);
int shortIntBytes = sizeof(short int);
int shortIntBits;
int intBytes = sizeof(int);
int intBits;
int longIntBytes = sizeof(long int);
int longIntBits;
int floatBytes = sizeof(float);
int floatBits;
int doubleBytes = sizeof(double);
int doubleBits;
printf("The size of data type 'char' is %d bytes, or %d bits.\n",
charBytes, CHAR_BIT);
printf("The minimum value for the unsigned 'char' data type is %d.\n",
CHAR_MIN);
printf("The maximum value for the unsigned 'char' data type is %d.\n",
CHAR_MAX);
printf("The minimum value for the signed 'char' data type is %d.\n",
SCHAR_MIN);
printf("The maximum value for the signed 'char' data type is %d.\n\n",
SCHAR_MAX);
shortIntBits = shortIntBytes * BITS_PER_BYTE;
printf("The size of data type 'short int' is %d bytes, or %d bits.\n",
shortIntBytes, shortIntBits);
printf("The minimum value for the signed 'short int' data type is %d.\n",
SHRT_MIN);
printf("The maximum value for the signed 'short int' data type is %d.\n\n",
SHRT_MAX);
intBits = intBytes * BITS_PER_BYTE;
printf("The size of data type 'int' is %d bytes, or %d bits.\n",
intBytes, intBits);
printf("The minimum value for the signed 'int' data type is %d.\n",
INT_MIN);
printf("The maximum value for the signed 'int' data type is %d.\n\n",
INT_MAX);
longIntBits = longIntBytes * BITS_PER_BYTE;
printf("The size of data type 'long int' is %d bytes, or %d bits.\n",
longIntBytes, longIntBits);
printf("The minimum value for the signed 'long int' data type is %d.\n",
LONG_MIN);
printf("The maximum value for the signed 'long int' data type is %d.\n\n",
LONG_MAX);
floatBits = floatBytes * BITS_PER_BYTE;
printf("The size of data type 'float' is %d bytes, or %d bits.\n",
floatBytes, floatBits);
printf("The minimum value for the 'float' data type is %lf.\n",
FLT_MIN);
printf("The maximum value for the 'float' data type is %lf.\n\n",
FLT_MAX);
doubleBits = doubleBytes * BITS_PER_BYTE;
printf("The size of data type 'double is %d bytes, or %d bits.\n",
doubleBytes, doubleBits);
printf("The minimum value for the 'double' data type is %lf.\n",
DBL_MIN);
printf("The maximum value for the 'double' data type is %lf.\n\n",
DBL_MAX);
}
Sample Output:
The size of data type 'char' is 1 bytes, or 8 bits.
The minimum value for the unsigned 'char' data type is 0.
The maximum value for the unsigned 'char' data type is 255.
The minimum value for the signed 'char' data type is -128.
The maximum value for the signed 'char' data type is 127.
The size of data type 'short int' is 2 bytes, or 16 bits.
The minimum value for the signed 'short int' data type is -32768.
The maximum value for the signed 'short int' data type is 32767.
The size of data type 'int' is 2 bytes, or 16 bits.
The minimum value for the signed 'int' data type is -32768.
The maximum value for the signed 'int' data type is 32767.
The size of data type 'long int' is 4 bytes, or 32 bits.
The minimum value for the signed 'long int' data type is 0.
The maximum value for the signed 'long int' data type is -1.
The size of data type 'float' is 4 bytes, or 32 bits.
The minimum value for the 'float' data type is %f.
The maximum value for the 'float' data type is %f.
The size of data type 'double is 4 bytes, or 32 bits.
The minimum value for the 'double' data type is %f.
The maximum value for the 'double' data type is %f.
This post has been edited by macosxnerd101: 30 January 2011 - 11:10 PM
Reason for edit:: Fixed end code tag

New Topic/Question
Reply




MultiQuote





|