分在C数据类型的最大值 [英] min and max value of data type in C

查看:90
本文介绍了分在C数据类型的最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的功能是什么,以确定在C最小和最大可能的数据类型(即,INT,char.etc)的价值?

What is the function to determine the min and max possible of value of datatypes (i.e, int, char.etc) in C?

推荐答案

您需要使用的 limits.h中 它提供了以下常量(按照链接参考):

You'll want to use limits.h which provides the following constants (as per the linked reference):

CHAR_BIT   = number of bits in a char
SCHAR_MIN  = minimum value for a signed char
SCHAR_MAX  = maximum value for a signed char
UCHAR_MAX  = maximum value for an unsigned char
CHAR_MIN   = minimum value for a char
CHAR_MAX   = maximum value for a char
MB_LEN_MAX = maximum multibyte length of a character accross locales
SHRT_MIN   = minimum value for a short
SHRT_MAX   = maximum value for a short
USHRT_MAX  = maximum value for an unsigned short
INT_MIN    = minimum value for an int
INT_MAX    = maximum value for an int
UINT_MAX   = maximum value for an unsigned int
LONG_MIN   = minimum value for a long
LONG_MAX   = maximum value for a long
ULONG_MAX  = maximum value for an unsigned long
LLONG_MIN  = minimum value for a long long
LLONG_MAX  = maximum value for a long long
ULLONG_MAX = maximum value for an unsigned long long

其中, U * _min 省略出于显而易见的原因(任何无符号类型为0,最小值)。

Where U*_MIN is omitted for obvious reasons (any unsigned type has a minimum value of 0).

float.h时 为限制浮动双击类型:

FLT_MIN  = min value of a float
FLT_MAX  = max value of a float
DBL_MIN  = min value of a double
DBL_MAX  = max value of a double
LDBL_MIN = min value of a long double
LDBL_MAX = max value of a long double

您应该阅读 floats.h 小心,虽然浮动双击文章可以容纳prescribed最小值和最大值,但precision与每个类型都可以重新present数据可能不匹配的是什么你想存储。特别是,它很难格外大量存储与附加极小部分。因此, float.h时提供了许多其他的常量帮助您确定是否浮动就可以了,其实,再present一个特定的号码。

You should read the article on floats.h carefully, though float and double can hold the prescribed minimum and maximum values but the precision with which each type can represent data may not match what it is you're trying to store. In particular, it's difficult to store exceptionally large numbers with extremely small fractions attached. So float.h provides a number of other constants that help you to determine if a float or a double can,in fact,represent a particular number.

这篇关于分在C数据类型的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆