C++ program to find the range of data types
kw.cpp
#include <iostream>
#include <stdlib.h>
#include <climits>
#include <cmath>
#include <stdio.h>
#include <float.h>
using namespace std;
int main()
{
    cout<<"———————————————————————————————————————————";
    cout<<"\nProgram to print the range of data types";
    cout<<"\n———————————————————————————————————————————\n";
    cout<<"   Signed char  | "<<SCHAR_MIN<<" To "<<SCHAR_MAX<<"\n";
    cout<<" Unsigned char  |  0"<<" To "<<UCHAR_MAX<<"\n";
    cout<<"  Signed short  | "<<SHRT_MIN<<" To "<<SHRT_MAX<<"\n";
    cout<<" Unsigned short |  0"<<" To "<<USHRT_MAX<<"\n";
    cout<<"   Signed  int  | "<<INT_MIN<<" To "<<INT_MAX<<"\n";
    cout<<" Unsigned  int  |  0"<<" To "<<UINT_MAX<<"\n";
    cout<<"   Signed long  | "<<LONG_MIN<<" To "<<LONG_MAX<<"\n";
    cout<<" Unsigned long  |  0"<<" To "<<ULONG_MAX<<"\n";
    cout<<"         float  | "<<FLT_MIN<<" To "<<FLT_MAX<<"\n";
    cout<<"        double  | "<<DBL_MIN<<" To "<<DBL_MAX<<"\n";
    cout<<"———————————————————————————————————————————\n";

    cout<<"   Signed char  | "<<pow(-2, (1 * CHAR_BIT) - 1)<<" To "<<pow(+2, (1 * CHAR_BIT) - 1) - 1<<"\n";
    cout<<" Unsigned char  |  0"<<" To "<<pow(+2, (1 * CHAR_BIT)) - 1<<"\n";
    cout<<"  Signed short  | "<<pow(-2, (2 * CHAR_BIT) - 1)<<" To "<<pow(+2, (2 * CHAR_BIT) - 1) - 1<<"\n";
    cout<<"Unsigned short  |  0"<<" To "<<pow(+2, (2 * CHAR_BIT)) - 1<<"\n";
    cout<<"   Signed  int  | "<<pow(-2, (4 * CHAR_BIT) - 1)<<" To "<<pow(+2, (4 * CHAR_BIT) - 1) - 1<<"\n";
    cout<<" Unsigned  int  |  0"<<" To "<<pow(+2, (4 * CHAR_BIT)) - 1<<"\n";
    cout<<"   Signed long  | "<<pow(-2, (8 * CHAR_BIT) - 1)<<" To "<<pow(+2, (8 * CHAR_BIT) - 1) - 1<<"\n";
    cout<<" Unsigned long  |  0"<<" To "<<pow(+2, (8 * CHAR_BIT)) - 1<<"\n";
    cout<<"———————————————————————————————————————————\n";
    return (EXIT_SUCCESS);
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to print the range of data types ——————————————————————————————————————————— Signed char | -128 To 127 Unsigned char | 0 To 255 Signed short | -32768 To 32767 Unsigned short | 0 To 65535 Signed int | -2147483648 To 2147483647 Unsigned int | 0 To 4294967295 Signed long | -9223372036854775808 To 9223372036854775807 Unsigned long | 0 To 18446744073709551615 float | 1.17549e-38 To 3.40282e+38 double | 2.22507e-308 To 1.79769e+308 ——————————————————————————————————————————— Signed char | -128 To 127 Unsigned char | 0 To 255 Signed short | -32768 To 32767 Unsigned short | 0 To 65535 Signed int | -2.14748e+09 To 2.14748e+09 Unsigned int | 0 To 4.29497e+09 Signed long | -9.22337e+18 To 9.22337e+18 Unsigned long | 0 To 1.84467e+19 ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement