Q1 Write a c program to show the data types, their ranges, sizes in bytes and format specifiers.

Write a program to show the data types, their ranges, sizes and format specifiers.

Program: 139

Write a c program to show the data types, their ranges, sizes in bytes and format specifiers.

Data TypeRangeBytesFormat Specifier
signed char-128 to +1271%c
unsigned char0 to 2551%c
short signed int-32,768 to +32,7672%hd
short unsigned int0 to 65,5352%hu
signed int-2,147,483,648 to 2,147,483,6474%d or %i
unsigned int0 to 4,294,967,2954%u
long signed int-2,147,483,648 to 2,147,483,6474%ld or %li
long unsigned int0 to 4,294,967,2954%lu
long long int-9,223,372,036,854,775,808 to 9,223,372,036,854,775,8078%lld or %lli
unsigned long long int0 to 18,446,744,073,709,551,6158%llu
float3.4E +/- 38 (7 digits)4%f
double1.7E +/- 308 (15 digits)8%lf
long doubleSame as double10%Lf or %e or %E
bool0 and 11%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

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.