#include <iostream> #include <string> #include <limits> using namespace std;
int main () {cout << "type: \t\t" << "************size**************" << Endl;
cout << "bool: \t\t" << "The number of bytes:" << sizeof (BOOL);
cout << "T max:" << (Numeric_limits<bool>::max) ();
cout << "\t\t min:" << (Numeric_limits<bool>::min) () << Endl;
cout << "char: \t\t" << "bytes:" << sizeof (char);
cout << "T max:" << (Numeric_limits<char>::max) ();
cout << "\t\t min:" << (Numeric_limits<char>::min) () << Endl;
cout << "signed char: \ t" << "number of bytes:" << sizeof (signed char);
cout << "T max:" << (numeric_limits<signed Char>::max) ();
cout << "\t\t min:" << (numeric_limits<signed char>::min) () << Endl; cout << "unsigned char: \ t" << "number of bytes:" << sizeof (unsignEd Char);
cout << "T max:" << (numeric_limits<unsigned Char>::max) ();
cout << "\t\t min:" << (numeric_limits<unsigned char>::min) () << Endl;
cout << "wchar_t: \ T" << "bytes:" << sizeof (wchar_t);
cout << "T max:" << (Numeric_limits<wchar_t>::max) ();
cout << "\t\t min:" << (Numeric_limits<wchar_t>::min) () << Endl;
cout << "short: \t\t" << "The number of bytes:" << sizeof (short);
cout << "T max:" << (Numeric_limits<short>::max) ();
cout << "\t\t min:" << (Numeric_limits<short>::min) () << Endl;
cout << "int: \t\t" << "number of bytes: << sizeof (int);
cout << "T max:" << (Numeric_limits<int>::max) ();
cout << "\ t min:" << (Numeric_limits<int>::min) () << Endl;
cout << "unsigned: \ T" << "bytes:" << sizeof (unsigned); cout << "\ t mostLarge value: "<< (Numeric_limits<unsigned>::max) ();
cout << "\ t min:" << (Numeric_limits<unsigned>::min) () << Endl;
cout << "Long: \t\t" << "number of bytes:" << sizeof (long);
cout << "T max:" << (Numeric_limits<long>::max) ();
cout << "\ t min:" << (Numeric_limits<long>::min) () << Endl;
cout << "unsigned long: \ T" << "the number of bytes:" << sizeof (unsigned long);
cout << "T max:" << (numeric_limits<unsigned Long>::max) ();
cout << "\ t min:" << (numeric_limits<unsigned long>::min) () << Endl;
cout << "double: \ T" << "bytes:" << sizeof (double);
cout << "T max:" << (Numeric_limits<double>::max) ();
cout << "\ t min:" << (Numeric_limits<double>::min) () << Endl;
cout << "long double: \ t" << "the number of bytes:" << sizeof (long double); cout << "\ t max:" << (Numeric_limits<long Double>::max)
();
cout << "\ t min:" << (Numeric_limits<long double>::min) () << Endl;
cout << "float: \t\t" << "number of bytes: << sizeof (float);
cout << "T max:" << (Numeric_limits<float>::max) ();
cout << "\ t min:" << (Numeric_limits<float>::min) () << Endl;
cout << "size_t: \ T" << "bytes:" << sizeof (size_t);
cout << "T max:" << (Numeric_limits<size_t>::max) ();
cout << "\ t min:" << (Numeric_limits<size_t>::min) () << Endl;
cout << "string: \ T" << "bytes:" << sizeof (string) << Endl; << "\ t max:" << (Numeric_limits<string>::max) () << "\ t min:" << (numeric_limits<
String>::min) () << Endl;
cout << "type: \t\t" << "************size**************" << Endl;
return 0; }
/* Run result analysis:
The above results are clear, a few additional points:
Concept, Integer: An arithmetic type that represents integers, characters, and Boolean values is called an integral type (integral type).
About signed and unsigned types: int, stort, and Long are signed by default. To obtain an unsigned type, you must make the type unsigned, such as unsigned long. The unsigned int type can be abbreviated to unsigned, that is, unsigned after the addition of the other type specifier means unsigned int.
A byte represents eight bits, i.e.: 1byte = 8 bit;
Int:4byte = bit signed signed range: 2^31-1 ~ -2^31 namely: 2147483647 ~-2147483648 unsigned unsigned range: 2^32-1 ~ 0 namely: 4294967295 ~ 0
Long:4 byte = bit with int type
Double:8 byte = bit range: 1.79769e+308 ~ 2.22507e-308
Long Double:12 byte = bit range: 1.18973e+4932 ~ 3.3621e-4932
Float:4 byte = bit range: 3.40282e+038 ~ 1.17549e-038
The maximum number of integers, unsigned, long, unsigned long, and double can only be represented as 1 billion, meaning that they represent no more than 10 digits in decimal, that is, you can save all 9-bit ints. and short only can represent 5 digits;
In addition, for floating-point purposes: using the double type is basically not a mistake. Implicit precision loss in float type can not be neglected, and the cost of two-double precision calculation is negligible relative to single precision. In fact, on some machines, the double type is much faster than the float type calculation. A float can guarantee only 6 digits, while a double will guarantee at least 15 digits (digits after the decimal point), and a long double provides the precision that is often not necessary and takes up additional operating costs.
Double is 8 bytes A total of 64 bits, of which the number of decimal places accounted for 52, 2-^52=2.2204460492503130808472633361816e-16, the magnitude of 10^-16, it can ensure that all the accuracy of 2^-15.
On some machines, the run-time price of a long type is much higher than the cost of doing the same calculation with the int type, so you need to understand the details of the program before you calculate the type and compare the actual run-time performance costs of the long type with the int type.