Original link
- #include <iostream>
- #include <string>
- #include <limits>
- Using namespace std;
- int main ()
- {
- cout << "type: \t\t" << "************size**************" << Endl;
- cout << "bool: \t\t" << "occupied bytes:" << sizeof (bool);
- cout << "\ t max:" << (numeric_limits<Bool>::max) ();
- cout << "\t\t min:" << (numeric_limits<bool>::min) () << Endl;
- cout << "char: \t\t" << "occupied bytes:" << sizeof (char);
- cout << "\ t max:" << (numeric_limits<Char>::max) ();
- cout << "\t\t min:" << (numeric_limits<char>::min) () << Endl;
- cout << "signed char: \ t" << "Total 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" << "Total 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" << "Total 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" << "occupied bytes:" << sizeof (short);
- cout << "\ t max:" << (numeric_limits<Short>::max) ();
- cout << "\t\t min:" << (numeric_limits<short>::min) () << Endl;
- cout << "int: \t\t" << "occupied bytes:" << sizeof (int);
- cout << "\ t max:" << (numeric_limits<Int>::max) ();
- cout << "\ t min:" << (numeric_limits<int>::min) << Endl;
- cout << "unsigned: \ T" << "Total bytes:" << sizeof (unsigned);
- cout << "\ t max:" << (Numeric_limits<unsigned>::max) ();
- cout << "\ t min:" << (Numeric_limits<unsigned>::min) () << Endl;
- cout << "long: \t\t" << "occupied bytes:" << sizeof (long);
- cout << "\ t max:" << (numeric_limits<Long>::max) ();
- cout << "\ t min:" << (numeric_limits<long>::min) << Endl;
- cout << "unsigned long: \ t" << "occupied bytes:" << sizeof (unsigned long);
- cout << "\ t max:" << (numeric_limits<unsigned Long>::max) ();
- cout << "\ t min:" << (numeric_limits<unsigned long>::min) << Endl;
- cout << "double: \ T" << "Total bytes:" << sizeof (double);
- cout << "\ t max:" << (numeric_limits<Double>::max) ();
- cout << "\ t min:" << (numeric_limits<double>::min) << Endl;
- cout << "long double: \ t" << "occupied 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" << "occupied bytes:" << sizeof (float);
- cout << "\ t max:" << (numeric_limits<Float>::max) ();
- cout << "\ t min:" << (numeric_limits<float>::min) << Endl;
- cout << "size_t: \ T" << "Total bytes:" << sizeof (size_t);
- cout << "\ t max:" << (numeric_limits<Size_t>::max) ();
- cout << "\ t min:" << (numeric_limits<size_t>::min) << Endl;
- cout << "string: \ T" << "Total bytes:" << sizeof (string) << Endl;
- //<< "\ t maximum:" << (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 have been very clear, a few additional notes:
Concept, Integer: An arithmetic type that represents integers, characters, and Booleans is called an integer (integral type).
About signed and unsigned types: integer int, stort, and Long are signed by default. To get the unsigned type, you must make the type unsigned, such as unsigned long. The unsigned int type can be abbreviated to unsigned, that is, unsigned no other type specifier means unsigned int.
A byte represents eight bits, namely: 1byte = 8 bit;
Int:4byte = 0 bit signed signed range: 2^31-1 ~ -2^31, i.e.: 2147483647 ~ 2147483648 unsigned unsigned range: 2^32-1 ~ 0 i.e.: 4294967295 ~
Long:4 byte = + bit with int type
Double:8 byte = bit range: 1.79769e+308 ~ 2.22507e-308
Long Double:12 byte = 1.18973e+4932 bit range: 3.3621e-4932
Float:4 byte = a bit range: 3.40282e+038 ~ 1.17549e-038
The order of magnitude of int, unsigned, long, unsigned long, and double can only be represented as 1 billion, meaning that they represent no more than 10 decimal digits, that is, all 9-bit integers can be saved. and short can only represent 5 bits;
In addition, for floating point, there is basically no mistake in using a double type. The implicit precision loss in float type can not be neglected, and the cost of two-double precision calculation is negligible relative to the single precision. In fact, on some machines, the double type is much faster than the float type calculation. The float type can only guarantee 6 digits, while the double type guarantees at least 15 significant digits (digits after the decimal point), and the precision provided by the long double type is usually unnecessary and bears additional operating costs.
Double is a total of 8 bytes of 64 bits, of which the decimal place occupies 52 bits, 2-^52=2.2204460492503130808472633361816e-16, magnitude of 10^-16, it can guarantee all the accuracy of 2^-15.
On some machines, the run-time price of a long type is much higher than the cost of the same calculation with the int type, so it is necessary to understand the details of the program before calculating the type and compare the actual run-time performance cost of the long type with the int type.
Various types of int, long, double, char for range (maximum minimum)