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 a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter.

Body Mass Index (BMI) is a measure of health based on height and weight. You can calculate your BMI by taking your weight in kilograms and dividing it by the square of your height in meters

Write a program that prompts the user to enter the coordinates of two points (x1, y1) and (x2, y2), and displays the slope of the line that connects the two points. The formula of the slope is (y2 - y1)/(x2 - x1).