c++ 数据类型

参考链接:http://www.cplusplus.com/reference/climits/


快速浏览各类型所能表示最大值:


nameexpressesvalue*
CHAR_BITNumber of bits in a char object (byte)8 or greater*
SCHAR_MINMinimum value for an object of type signed char-127 (-27+1) or less*
SCHAR_MAXMaximum value for an object of type signed char127 (27-1) or greater*
UCHAR_MAXMaximum value for an object of type unsigned char255 (28-1) or greater*
CHAR_MINMinimum value for an object of type chareither SCHAR_MIN or 0
CHAR_MAXMaximum value for an object of type chareither SCHAR_MAX or UCHAR_MAX
MB_LEN_MAXMaximum number of bytes in a multibyte character, for any locale1 or greater*
SHRT_MINMinimum value for an object of type short int-32767 (-215+1) or less*
SHRT_MAXMaximum value for an object of type short int32767 (215-1) or greater*
USHRT_MAXMaximum value for an object of type unsigned short int65535 (216-1) or greater*
INT_MINMinimum value for an object of type int-32767 (-215+1) or less*
INT_MAXMaximum value for an object of type int32767 (215-1) or greater*
UINT_MAXMaximum value for an object of type unsigned int65535 (216-1) or greater*
LONG_MINMinimum value for an object of type long int-2147483647 (-231+1) or less*
LONG_MAXMaximum value for an object of type long int2147483647 (231-1) or greater*
ULONG_MAXMaximum value for an object of type unsigned long int4294967295 (232-1) or greater*
LLONG_MINMinimum value for an object of type long long int-9223372036854775807 (-263+1) or less*
LLONG_MAXMaximum value for an object of type long long int9223372036854775807 (263-1) or greater*
ULLONG_MAXMaximum value for an object of type unsigned long long int18446744073709551615 (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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值