c++ 数据类型

来源:互联网 发布:无线网址域名注册 编辑:程序博客网 时间:2024/06/05 15:58

参考链接: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 0CHAR_MAXMaximum value for an object of type chareither SCHAR_MAX or UCHAR_MAXMB_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

Tstd::numeric_limits<T>::min()/* non-specialized */T();boolfalsecharCHAR_MINsigned charSCHAR_MINunsigned char0wchar_tWCHAR_MINchar16_t0char32_t0shortSHRT_MINunsigned short0intINT_MINunsigned int0longLONG_MINunsigned long0long longLLONG_MINunsigned long long0floatFLT_MINdoubleDBL_MINlong doubleLDBL_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 0x8000int: -2147483648 or 0x80000000ptrdiff_t: -9223372036854775808 or 0x8000000000000000float: 1.17549e-38 or 0x1p-126double: 2.22507e-308 or 0x1p-1022

0 0
原创粉丝点击