#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 max:" << (Numeric_limits<string>::max) () << "\ t min:" << (numeric_limits< String>::min) () << Endl; cout << "type: \t\t" << "************size**************" << Endl; return 0;}
/* Perform result analysis:
The above results are 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 specified feel signed. To get an unsigned type, you must make the unsigned, for example, unsigned long. The unsigned int type can be shortened to unsigned, that is, no other type descriptor after unsigned means unsigned int.
A byte represents eight bits, namely: 1byte = 8 bit;
Int:4byte = A signed signed range: 2^31-1 ~ -2^31 : 2147483647 ~ -2147483648 unsigned unsigned range: 2^32-1 ~ 0 that is: 4294967295 ~ 0
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, which means that all 9-bit integers can be saved. And short is only able to 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 only guarantees 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 carries additional execution costs.
Double is 8 bytes total 64 bits, when the small and medium digit occupies 52 bits, 2-^52=2.2204460492503130808472633361816e-16, the magnitude is 10^-16, therefore can guarantee 2^-15 all precision.
On some machines, the execution 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 and the performance cost compared to the actual execution of the long type and the int type before calculating the type.
Welcome to make valuable comments to help me improve, greatly appreciated!!!
--Songhai Finishing
Various types of int, long, double, char for range (maximum minimum)