Variable limits and size of variable in byte program cpp


Limit of variable and size of variable
#Beginner #Intermediate

In gcc c++ compiler using namespace std;



#include<iostream>
#include<limits>
using namespace std;

int main()
{
cout<<"-------------------signed variable------------------------"<<endl;
cout<<"variable | minimum value  | maximum value  |  size in byte"<<endl;
cout<<"Char \t\t"<<CHAR_MIN<<"\t\t"<<CHAR_MAX<<"\t\t\t"<<sizeof(char)<<endl;
cout<<"short int \t"<<SHRT_MIN<<"\t\t"<<SHRT_MAX<<"\t\t\t"<<sizeof(short int)<<endl;
cout<<"int \t\t"<<INT_MIN<<"\t"<<INT_MAX<<"\t\t"<<sizeof(int)<<endl;
cout<<"long int \t"<<LONG_MIN<<"\t"<<LONG_MAX<<"\t\t"<<sizeof(long int)<<endl;
cout<<"long long  "<<LLONG_MIN<<"\t"<<LLONG_MAX<<"\t"<<sizeof(long long)<<endl;
cout<<"float \t\t"<<FLT_MIN<<"\t"<<FLT_MAX<<"\t\t"<<sizeof(float)<<endl;
cout<<"double \t\t"<<DBL_MIN<<"\t"<<DBL_MAX<<"\t\t"<<sizeof(double)<<endl;
cout<<"long double \t"<<LDBL_MIN<<"\t"<<LDBL_MAX<<"\t\t"<<sizeof(long double)<<endl;
cout<<endl;
    cout<<endl;
    cout<<endl;
cout<<"-------------------unsigned variable------------------------"<<endl;
cout<<"variable | minimum value  | maximum value  |  size in byte"<<endl;
cout<<"Char \t\t"<<0<<"\t\t"<<UCHAR_MAX<<"\t\t\t"<<sizeof(char)<<endl;
cout<<"short int \t"<<0<<"\t\t"<<USHRT_MAX<<"\t\t\t"<<sizeof(short int)<<endl;
cout<<"int \t\t"<<0<<"\t\t"<<UINT_MAX<<"\t\t"<<sizeof(int)<<endl;
cout<<"long int \t"<<0<<"\t\t"<<ULONG_MAX<<"\t\t"<<sizeof(long int)<<endl;
cout<<"long long  \t"<<0<<"\t\t"<<ULLONG_MAX<<"\t"<<sizeof(long long)<<endl;
return 0;
}
copy


Output

-------------------signed variable------------------------
variable | minimum value  | maximum value  |  size in byte
Char                             0               255                                              1
short int                 -32768          32767                                          2
int                      -2147483648     2147483647                               4
long int             -2147483648     2147483647                               4
long long  -9223372036854775808  9223372036854775807   8
float                     1.17549e-38     3.40282e+38                             4
double                2.22507e-308    1.79769e+308                          8
long double.      2.22507e-308    1.79769e+308                          8



-------------------unsigned variable------------------------
variable | minimum value  | maximum value  |  size in byte
Char                          0                               255                     1
short int                   0                             65535                   2
int                             0                        4294967295              4
long int                    0                        4294967295              4
long long               0               18446744073709551615    8

[Program finished]

Need of Programmer

Need of Programmer

Comments

Popular posts from this blog

Write a program that reads in the radius and length of a cylinder and computes the area and volume using the following formulas: area = radius * radius * π volume = area * length

Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total.

Write a program that prompts the user to enter the min- utes (e.g., 1 billion), and displays the number of years and days for the minutes. For simplicity, assume a year has 365 days