Program: 139
Write a c program to show the data types, their ranges, sizes in bytes and format specifiers.
Data Type | Range | Bytes | Format Specifier |
signed char | -128 to +127 | 1 | %c |
unsigned char | 0 to 255 | 1 | %c |
short signed int | -32,768 to +32,767 | 2 | %hd |
short unsigned int | 0 to 65,535 | 2 | %hu |
signed int | -2,147,483,648 to 2,147,483,647 | 4 | %d or %i |
unsigned int | 0 to 4,294,967,295 | 4 | %u |
long signed int | -2,147,483,648 to 2,147,483,647 | 4 | %ld or %li |
long unsigned int | 0 to 4,294,967,295 | 4 | %lu |
long long int | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 8 | %lld or %lli |
unsigned long long int | 0 to 18,446,744,073,709,551,615 | 8 | %llu |
float | 3.4E +/- 38 (7 digits) | 4 | %f |
double | 1.7E +/- 308 (15 digits) | 8 | %lf |
long double | Same as double | 10 | %Lf or %e or %E |
bool | 0 and 1 | 1 | %d or %i |
#include<stdio.h> //for using bool DataType we used this header file #include<stdbool.h> int main() { //character char c; unsigned char d; //integer int i; unsigned int j; short int k=0; unsigned short int l=0; long int m; unsigned long int n; long long int o; unsigned long long int p; //floating point float x; double y; long double z; //boolean - for using bool DataType we have to import //<stdbool.h> header file bool b; /* char */ c=-65; d=65; printf("Size of signed char(%c): %d byte\n",c,sizeof(c)); printf("Size of unsigned char(%c): %d byte\n",d,sizeof(d)); /* short int */ k=-12345; l=12345; printf("\nSize of signed short int(%hi): %d byte\n",k,sizeof(k)); printf("Size of unsigned short int(%hu): %d byte\n",l,sizeof(l)); /* int */ i=-123456789; j=123456789; printf("\nSize of signed int(%d): %d byte\n",i,sizeof(i)); printf("Size of unsigned int(%u): %d byte\n",j,sizeof(j)); /* long int */ m=-123456789; n=123456789; printf("\nSize of signed long int(%ld): %d byte\n",m,sizeof(m)); printf("Size of unsigned long int(%lu): %d byte\n",n,sizeof(n)); /* long long int */ o=-123456789; p=123456789; printf("\nSize of signed long long int(%lld): %d byte\n",o,sizeof(o)); printf("Size of unsigned long long int(%llu): %d byte\n",p,sizeof(p)); /* float, double, long double */ x=y=z=2.123456789; printf("\nSize of float(%f): %d bytes\n",x,sizeof(x)); printf("Size of double(%lf): %d bytes\n",y,sizeof(y)); printf("Size of long double(%E): %d bytes\n",z,sizeof(z)); /* char */ b=true; printf("Size of bool(%d): %d byte\n",b,sizeof(b)); }
Output:
Size of signed char(┐): 1 byte Size of unsigned char(A): 1 byte Size of signed short int(-12345): 2 byte Size of unsigned short int(12345): 2 byte Size of signed int(-123456789): 4 byte Size of unsigned int(123456789): 4 byte Size of signed long int(-123456789): 4 byte Size of unsigned long int(123456789): 4 byte Size of signed long long int(-123456789): 8 byte Size of unsigned long long int(123456789): 8 byte Size of float(2.123457): 4 bytes Size of double(2.123457): 8 bytes Size of long double(3.172866E-317): 16 bytes Size of bool(1): 1 byte
Leave a Comment