Answer:
#include <iostream>
#include <limits>
using namespace std;
int main() {
// integer data types
cout << "Size and range of integer data types:" << endl;
cout << "------------------------------------" << endl;
cout << "char: " << sizeof(char) << " bytes, "
<< static_cast<int>(numeric_limits<char>::min()) << " to "
<< static_cast<int>(numeric_limits<char>::max()) << endl;
cout << "short: " << sizeof(short) << " bytes, "
<< numeric_limits<short>::min() << " to "
<< numeric_limits<short>::max() << endl;
cout << "int: " << sizeof(int) << " bytes, "
<< numeric_limits<int>::min() << " to "
<< numeric_limits<int>::max() << endl;
cout << "long: " << sizeof(long) << " bytes, "
<< numeric_limits<long>::min() << " to "
<< numeric_limits<long>::max() << endl;
cout << "long long: " << sizeof(long long) << " bytes, "
<< numeric_limits<long long>::min() << " to "
<< numeric_limits<long long>::max() << endl;
// real number data types
cout << endl;
cout << "Size and range of real number data types:" << endl;
cout << "---------------------------------------" << endl;
cout << "float: " << sizeof(float) << " bytes, "
<< numeric_limits<float>::min() << " to "
<< numeric_limits<float>::max() << endl;
cout << "double: " << sizeof(double) << " bytes, "
<< numeric_limits<double>::min() << " to "
<< numeric_limits<double>::max() << endl;
cout << "long double: " << sizeof(long double) << " bytes, "
<< numeric_limits<long double>::min() << " to "
<< numeric_limits<long double>::max() << endl;
return 0;
}
Step-by-step explanation:
The program uses the sizeof operator to determine the size of each data type in bytes, and the numeric_limits class template from the <limits> header to print the minimum and maximum values for each data type. The static_cast<int> is used to cast the char data type to an int so that its minimum and maximum values can be printed as integers.