参考链接:http://www.cplusplus.com/reference/climits/
快速浏览各类型所能表示最大值:
name | expresses | value* |
---|---|---|
CHAR_BIT | Number of bits in a char object (byte) | 8 or greater* |
SCHAR_MIN | Minimum value for an object of type signed char | -127 (-27+1 ) or less* |
SCHAR_MAX | Maximum value for an object of type signed char | 127 (27-1 ) or greater* |
UCHAR_MAX | Maximum value for an object of type unsigned char | 255 (28-1 ) or greater* |
CHAR_MIN | Minimum value for an object of type char | either SCHAR_MIN or 0 |
CHAR_MAX | Maximum value for an object of type char | either SCHAR_MAX or UCHAR_MAX |
MB_LEN_MAX | Maximum number of bytes in a multibyte character, for any locale | 1 or greater* |
SHRT_MIN | Minimum value for an object of type short int | -32767 (-215+1 ) or less* |
SHRT_MAX | Maximum value for an object of type short int | 32767 (215-1 ) or greater* |
USHRT_MAX | Maximum value for an object of type unsigned short int | 65535 (216-1 ) or greater* |
INT_MIN | Minimum value for an object of type int | -32767 (-215+1 ) or less* |
INT_MAX | Maximum value for an object of type int | 32767 (215-1 ) or greater* |
UINT_MAX | Maximum value for an object of type unsigned int | 65535 (216-1 ) or greater* |
LONG_MIN | Minimum value for an object of type long int | -2147483647 (-231+1 ) or less* |
LONG_MAX | Maximum value for an object of type long int | 2147483647 (231-1 ) or greater* |
ULONG_MAX | Maximum value for an object of type unsigned long int | 4294967295 (232-1 ) or greater* |
LLONG_MIN | Minimum value for an object of type long long int | -9223372036854775807 (-263+1 ) or less* |
LLONG_MAX | Maximum value for an object of type long long int | 9223372036854775807 (263-1 ) or greater* |
ULLONG_MAX | Maximum value for an object of type unsigned long long int | 18446744073709551615 (264-1 ) or greater* |
c++标准库中查看类型最小值方法:
http://en.cppreference.com/w/cpp/types/numeric_limits/min
std::numeric_limits::min()
Return value
T | std::numeric_limits<T>::min() |
/* non-specialized */ | T(); |
bool | false |
char | CHAR_MIN |
signed char | SCHAR_MIN |
unsigned char | 0 |
wchar_t | WCHAR_MIN |
char16_t | 0 |
char32_t | 0 |
short | SHRT_MIN |
unsigned short | 0 |
int | INT_MIN |
unsigned int | 0 |
long | LONG_MIN |
unsigned long | 0 |
long long | LLONG_MIN |
unsigned long long | 0 |
float | FLT_MIN |
double | DBL_MIN |
long double | LDBL_MIN |
#include <limits> #include <cstddef> #include <iostream> int main() { std::cout << "short: " << std::dec << std::numeric_limits<short>::min() << " or " << std::hex << std::showbase << std::numeric_limits<short>::min() << '\n' << "int: " << std::dec << std::numeric_limits<int>::min() << std::showbase << " or " << std::hex << std::numeric_limits<int>::min() << '\n' << std::dec << "ptrdiff_t: " << std::numeric_limits<std::ptrdiff_t>::min() << std::showbase << " or " << std::hex << std::numeric_limits<std::ptrdiff_t>::min() << '\n' << "float: " << std::numeric_limits<float>::min() << " or " << std::hexfloat << std::numeric_limits<float>::min() << '\n' << "double: " << std::defaultfloat << std::numeric_limits<double>::min() << " or " << std::hexfloat << std::numeric_limits<double>::min() << '\n'; }
short: -32768 or 0x8000 int: -2147483648 or 0x80000000 ptrdiff_t: -9223372036854775808 or 0x8000000000000000 float: 1.17549e-38 or 0x1p-126 double: 2.22507e-308 or 0x1p-1022