Source of limits.cpp


  1: //limits.cpp
  2: //Displays constant values associated with various data types.

  4: #include <iostream>
  5: #include <climits>
  6: #include <cfloat>
  7: using namespace std;

  9: int main()
 10: {
 11:     cout << "\nThis program displays maximum and minimum "
 12:          << "values for simple C++ data types.\n\n";

 14:     //The following named constants are defined in <climits>:
 15:     cout << "Number of bits in a byte  " << CHAR_BIT  << endl;
 16:     cout << "Maximum char value ...... " << CHAR_MAX  << "\t\t";
 17:     cout << "Minimum char value ...... " << CHAR_MIN  << endl;
 18:     cout << endl;
 19:     cout << "Maximum short value ..... " << SHRT_MAX  << "\t\t";
 20:     cout << "Minimum short value ..... " << SHRT_MIN  << endl;
 21:     cout << "Maximum int value ....... " << INT_MAX   << '\t';
 22:     cout << "Minimum int value ....... " << INT_MIN   << endl;
 23:     cout << "Maximum long value ...... " << LONG_MAX  << '\t';
 24:     cout << "Minimum long value ...... " << LONG_MIN  << endl;
 25:     cout << endl;
 26:     cout << "Maximum unsigned char value .... " << UCHAR_MAX << endl;
 27:     cout << "Maximum unsigned short value ... " << USHRT_MAX << endl;
 28:     cout << "Maximum unsigned int value ..... " << UINT_MAX  << endl;
 29:     cout << "Maximum unsigned long value .... " << ULONG_MAX << endl;
 30:     cout << endl;

 32:     //The following named constants are defined in <cfloat>:
 33:     cout << "Approx # of sig digits in a float ..... " << FLT_DIG  << endl;
 34:     cout << "Maximum positive float value .......... " << FLT_MAX  << endl;
 35:     cout << "Minimum positive float value .......... " << FLT_MIN  << endl;
 36:     cout << "Approx # of sig digits in a double .... " << DBL_DIG  << endl;
 37:     cout << "Maximum positive double value ......... " << DBL_MAX  << endl;
 38:     cout << "Minimum positive double value ......... " << DBL_MIN  << endl;
 39:     cout << "Approx # of sig digits in a long double " << LDBL_DIG << endl;
 40:     cout << "Maximum positive long double value .... " << LDBL_MAX << endl;
 41:     cout << "Minimum positive long double value .... " << LDBL_MIN << endl;
 42: }