int類型的變量存儲值從-2147483648到2147483647
1 //例子 2 #include <iostream> 3 2 using namespace std; 4 3 int main(void) 5 4 { 6 5 7 6 cout<<"int類型的取值范圍為:"<<INT_MIN<<"到"<<INT_MAX<<endl; 8 7 return 0; 9 8 }
unsigned int類型的變量存儲值從0到4294967295
1 //例子 2 #include <iostream> 3 using namespace std; 4 int main(void) 5 { 6 cout<<"unsigned int類型的取值范圍為:0到"<<UINT_MAX<<endl; 7 return 0; 8 }
short類型的變量存儲值從-32768到32767
unsigned short類型的變量存儲值從0到65535
char類型的變量存儲值從-128到127
unsigned char類型的變量存儲值從0到255
long類型的變量存儲值從-2147483648到2147483647
unsigned long類型的變量存儲值從0到4294967295
long long類型的變量存儲值從-9223372036854775808到9223372036854775807
unsigned long long類型的變量存儲值從0到18446744073709551615
最小的非零float類型變量的值的是1.175e-038
最大的float類型變量的值的是3.403e+038
最小的非零double類型變量的值的是2.225e-308
最大的double類型變量的值的是1.798e+308
最小的非零long double類型變量的值的是-0.000e+000
最大的long double類型變量的值的是-1.#QOe+000
float類型的變量提供6位精度的小數位數
double類型的變量提供15位精度的小數位數
long double類型的變量提供18位精度的小數位數
1 #include <stdio.h> 2 #include <limits.h> 3 #include <float.h> 4 #include <stdlib.h> 5 int main(void) 6 7 { 8 9 printf("char類型的變量存儲值從%d到%d\n", CHAR_MIN, CHAR_MAX); 10 11 printf("unsigned char類型的變量存儲值從0到%u\n", UCHAR_MAX); 12 13 printf("short類型的變量存儲值從%d到%d\n", SHRT_MIN, SHRT_MAX); 14 15 printf("unsigned short類型的變量存儲值從0到%u\n", USHRT_MAX); 16 17 printf("int類型的變量存儲值從%d到%d\n", INT_MIN, INT_MAX); 18 19 printf("unsigned int類型的變量存儲值從0到%u\n", UINT_MAX); 20 21 printf("long類型的變量存儲值從%ld到%ld\n", LONG_MIN, LONG_MAX); 22 23 printf("unsigned long類型的變量存儲值從0到%lu\n\n", ULONG_MAX); 24 25 printf("long long類型的變量存儲值從%lld到%lld\n", LLONG_MIN, LLONG_MAX); 26 27 printf("unsigned long long類型的變量存儲值從0到%llu\n", ULLONG_MAX); 28 29 printf("最小的非零float類型變量的值的是%.3e\n", FLT_MIN); 30 31 printf("最大的float類型變量的值的是%.3e\n", FLT_MAX); 32 33 printf("最小的非零double類型變量的值的是%.3e\n", DBL_MIN); 34 35 printf("最大的double類型變量的值的是%.3e\n\n", DBL_MAX); 36 37 printf("最小的非零long double類型變量的值的是%.3Le\n", LDBL_MIN); 38 39 printf("最大的long double類型變量的值的是%.3Le\n", LDBL_MAX); 40 41 printf("float類型的變量提供%u位精度的小數位數\n", FLT_DIG); 42 43 printf("double類型的變量提供%u位精度的小數位數\n\n", DBL_DIG); 44 45 printf("long double類型的變量提供%u位精度的小數位數\n", LDBL_DIG); 46 47 system("pause"); 48 49 return 0; 50 }
1 #include<iostream> 2 #include<string> 3 #include <limits> 4 using namespace std; 5 6 int main() 7 { 8 9 cout << "type: \t\t" << "************size**************"<< endl; 10 cout << "bool: \t\t" << "所占字節數:" << sizeof(bool); 11 cout << "\t最大值:" << (numeric_limits<bool>::max)(); 12 cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl; 13 cout << "char: \t\t" << "所占字節數:" << sizeof(char); 14 cout << "\t最大值:" << (numeric_limits<char>::max)(); 15 cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl; 16 cout << "signed char: \t" << "所占字節數:" << sizeof(signed char); 17 cout << "\t最大值:" << (numeric_limits<signed char>::max)(); 18 cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl; 19 cout << "unsigned char: \t" << "所占字節數:" << sizeof(unsigned char); 20 cout << "\t最大值:" << (numeric_limits<unsigned char>::max)(); 21 cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl; 22 cout << "wchar_t: \t" << "所占字節數:" << sizeof(wchar_t); 23 cout << "\t最大值:" << (numeric_limits<wchar_t>::max)(); 24 cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl; 25 cout << "short: \t\t" << "所占字節數:" << sizeof(short); 26 cout << "\t最大值:" << (numeric_limits<short>::max)(); 27 cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl; 28 cout << "int: \t\t" << "所占字節數:" << sizeof(int); 29 cout << "\t最大值:" << (numeric_limits<int>::max)(); 30 cout << "\t最小值:" << (numeric_limits<int>::min)() << endl; 31 cout << "unsigned: \t" << "所占字節數:" << sizeof(unsigned); 32 cout << "\t最大值:" << (numeric_limits<unsigned>::max)(); 33 cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl; 34 cout << "long: \t\t" << "所占字節數:" << sizeof(long); 35 cout << "\t最大值:" << (numeric_limits<long>::max)(); 36 cout << "\t最小值:" << (numeric_limits<long>::min)() << endl; 37 cout << "unsigned long: \t" << "所占字節數:" << sizeof(unsigned long); 38 cout << "\t最大值:" << (numeric_limits<unsigned long>::max)(); 39 cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl; 40 cout << "double: \t" << "所占字節數:" << sizeof(double); 41 cout << "\t最大值:" << (numeric_limits<double>::max)(); 42 cout << "\t最小值:" << (numeric_limits<double>::min)() << endl; 43 cout << "long double: \t" << "所占字節數:" << sizeof(long double); 44 cout << "\t最大值:" << (numeric_limits<long double>::max)(); 45 cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl; 46 cout << "float: \t\t" << "所占字節數:" << sizeof(float); 47 cout << "\t最大值:" << (numeric_limits<float>::max)(); 48 cout << "\t最小值:" << (numeric_limits<float>::min)() << endl; 49 cout << "size_t: \t" << "所占字節數:" << sizeof(size_t); 50 cout << "\t最大值:" << (numeric_limits<size_t>::max)(); 51 cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl; 52 cout << "string: \t" << "所占字節數:" << sizeof(string) << endl; 53 // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl; 54 cout << "type: \t\t" << "************size**************"<< endl; 55 return 0; 56 }