Q1) suppose you are programmer but you
have no user manual to see the size of different data types like int, double ,
float , char and long. Write a programm
that will calculate the size of this data types and display data type on
screen.
using namespace std;
int main()
{
int in,size_in;
float fl,size_fl;
double db,size_db;
long lg,size_lg;
short sh,size_sh;
cout<<"Enter int = ";
cin>>in;
size_in=sizeof (in);
cout<<"The size of int(data type) = "<<size_in<<endl<<"Data type is int. "<<endl<<endl;
cout<<"Enter float = ";
cin>>fl;
size_fl=sizeof (fl);
cout<<"The size of float(data type) = "<<size_fl<<endl<<"Data type is float. "<<endl<<endl;
cout<<"Enter double = ";
cin>>db;
size_db=sizeof (db);
cout<<"The size of double(data type) = "<<db<<endl<<"Data type is double."<<endl<<endl;
cout<<"Enter long = ";
cin>>lg;
size_lg=sizeof (lg);
cout<<"The size of long(data type) = "<<size_lg<<endl<<"Data type is long."<<endl<<endl;
cout<<"Enter short = ";
cin>>sh;
size_sh=sizeof (sh);
cout<<"The size of short(data type) = "<<size_sh<<endl<<"Data type is short"<<endl<<endl;
return 0;
}
No comments:
Post a Comment