Variable limits and size of variable in byte program cpp
#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;
}
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]
Comments
Post a Comment
Any doubt about programming or questions