In below program some defined macros in limits.h header is used to get the range of the data type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include <stdio.h> #include <limits.h> /*UCHAR_MIN is not defined in limits.h because minimum positive value is 0 always*/ #define UCHAR_MIN 0 #define UINT_MIN 0 #define USHRT_MIN 0 #define ULONG_MIN 0 int main(void) { /*********************size of Char***************************************/ printf("Size of char = %lu byte\n",sizeof(char)); printf("Size of signed char = %lu byte\n",sizeof(signed char)); printf("range of unsigned char = %lu byte\n\n",sizeof(unsigned char)); /********************Char RANGE***********************************************/ printf("range of char = %d to %d\n",CHAR_MIN,CHAR_MAX); printf("range of signed char = %d to %d\n",SCHAR_MIN,SCHAR_MAX); printf("range of unsigned char = %u to %u\n\n",UCHAR_MIN,UCHAR_MAX); /********************size of int************************************/ printf("Size of int= %lu byte\n",sizeof(int)); printf("Size of signed int= %lu byte\n",sizeof(signed int)); printf("range of unsigned int= %lu byte\n\n",sizeof(unsigned int)); /********************RANGE of int*****************************************/ printf("range of int= %d to %d\n",INT_MIN,INT_MAX); printf("range of signed int= %d to %d\n",INT_MIN,INT_MAX); printf("range of unsigned int= %u to %u\n\n",UINT_MIN,UINT_MAX); /********************size of short int*************************/ printf("Size of short int= %lu byte\n",sizeof(short int)); printf("Size of signed short int= %lu byte\n",sizeof(signed short int)); printf("range of unsigned short int= %lu byte\n\n",sizeof(unsigned short int)); /********************RANGE of short int************************************/ printf("range of short int= %d to %d\n",SHRT_MIN,SHRT_MAX); printf("range of signed short int= %d to %d\n",SHRT_MIN,SHRT_MAX); printf("range of unsigned short int= %u to %u\n\n",USHRT_MIN,USHRT_MAX); /********************size of long int*************************************/ printf("Size of long int= %lu byte\n",sizeof(long int)); printf("Size of signed long int= %lu byte\n",sizeof(signed long int)); printf("range of unsigned long int= %lu byte\n\n",sizeof(unsigned long int)); /********************RANGE of long int**************************************/ printf("range of long int= %ld to %ld\n",LONG_MIN,LONG_MAX); printf("range of signed long int= %ld to %ld\n",LONG_MIN,LONG_MAX); printf("range of unsigned long int= %lu to %lu\n\n",ULONG_MIN,ULONG_MAX); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
Output: Size of char = 1 byte Size of signed char = 1 byte range of unsigned char = 1 byte range of char = -128 to 127 range of signed char = -128 to 127 range of unsigned char = 0 to 255 Size of int= 4 byte Size of signed int= 4 byte range of unsigned int= 4 byte range of int= -2147483648 to 2147483647 range of signed int= -2147483648 to 2147483647 range of unsigned int= 0 to 4294967295 Size of short int= 2 byte Size of signed short int= 2 byte range of unsigned short int= 2 byte range of short int= -32768 to 32767 range of signed short int= -32768 to 32767 range of unsigned short int= 0 to 65535 Size of long int= 8 byte Size of signed long int= 8 byte range of unsigned long int= 8 byte range of long int= -9223372036854775808 to 9223372036854775807 range of signed long int= -9223372036854775808 to 9223372036854775807 range of unsigned long int= 0 to 18446744073709551615 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <stdio.h> #include <float.h> int main(void) { /*********************float**************************************/ printf("Size of float = %lu byte\n",sizeof(float)); printf("Decimal Digits without Precision Lost= till %lu digit \n",FLT_DIG); printf("range of float = %e to %e\n\n",FLT_MIN,FLT_MAX); /*********************double**************************************/ printf("Size of double = %lu byte\n",sizeof(double)); printf("Decimal Digits without Precision Lost= till %lu digit \n",DBL_DIG); printf("range of double = %le to %le\n\n",DBL_MIN,DBL_MAX); /*********************long double************************/ printf("Size of long double= %lu byte\n",sizeof(long double)); printf("Decimal Digits without Precision Lost= till %lu digit \n",LDBL_DIG); printf("range of long double= %Le to %Le\n\n",LDBL_MIN,LDBL_MAX); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 |
Output: Size of float = 4 byte Decimal Digits without Precision Lost= till 6 digit range of float = 1.175494e-38 to 3.402823e+38 Size of double = 8 byte Decimal Digits without Precision Lost= till 15 digit range of double = 2.225074e-308 to 1.797693e+308 Size of long double= 16 byte Decimal Digits without Precision Lost= till 18 digit range of long double= 3.362103e-4932 to 1.189731e+4932 |