以下符号表示整数类型的范围限制。类型最低限制最高限制charCHAR_MINCHAR_MAXshort
编程学习网为您整理以下代码实例,主要实现:不同类型的值的大小限制,希望可以帮到各位朋友。
以下符号表示整数类型的范围限制。
类型 | 最低限制 | 最高限制 |
---|---|---|
char | CHAR_MIN | CHAR_MAX |
short | SHRT_MIN | SHRT_MAX |
int | INT_MIN | INT_MAX |
long | LONG_MIN | LONG_MAX |
long long | LLONG_MIN | LLONG_MAX |
float | FLT_MIN | FLT_MAX |
double | DBL_MIN | DBL_MAX |
long double | LDBL_MIN | LDBL_MAX |
无符号整数类型的下限均为0。
对应于无符号整数类型的上限的符号是:UCHAR_MAX
,USHRT_MAX
,UINT_MAX
,ulONG_MAX
和ulLONG_MAX
。
以下代码将演示编译器的限制:
#include <stdio.h> // For command line input and output
#include <limits.h> // For limits on integer types
#include <float.h> // For limits on floating-point types
int main(voID){
printf("Variables of type char store values from %d to %d\n", CHAR_MIN, CHAR_MAX);
printf("Variables of type unsigned char store values from 0 to %u\n", UCHAR_MAX);
printf("Variables of type short store values from %d to %d\n", SHRT_MIN, SHRT_MAX);
printf("Variables of type unsigned short store values from 0 to %u\n", USHRT_MAX);
printf("Variables of type int store values from %d to %d\n", INT_MIN, INT_MAX);
printf("Variables of type unsigned int store values from 0 to %u\n", UINT_MAX);
printf("Variables of type long store values from %ld to %ld\n", LONG_MIN, LONG_MAX);
printf("Variables of type unsigned long store values from 0 to %lu\n", ulONG_MAX);
printf("Variables of type long long store values from %lld to %lld\n", LLONG_MIN, LLONG_MAX);
printf("Variables of type unsigned long long store values from 0 to %llu\n", ulLONG_MAX);
printf("\nThe size of the smallest positive non-zero value of type float is %.3e\n", FLT_MIN);
printf("The size of the largest value of type float is %.3e\n", FLT_MAX);
printf("The size of the smallest non-zero value of type double is %.3e\n", DBL_MIN);
printf("The size of the largest value of type double is %.3e\n", DBL_MAX);
printf("The size of the smallest non-zero value of type long double is %.3Le\n", LDBL_MIN);
printf("The size of the largest value of type long double is %.3Le\n", LDBL_MAX);
printf("\n Variables of type float provIDe %u decimal digits precision. \n", FLT_DIG);
printf("Variables of type double provIDe %u decimal digits precision. \n", DBL_DIG);
printf("Variables of type long double provIDe %u decimal digits precision. \n",
LDBL_DIG);
int number = INT_MAX;
printf("%d",number);
return 0;
}
沃梦达教程
本文标题为:不同类型的值的大小限制
基础教程推荐
猜你喜欢
- 分别使用%o和%x以八进制或十六进制格式显示整 1970-01-01
- end() 能否成为 stl 容器的昂贵操作 2022-10-23
- 明确指定任何或所有枚举数的整数值 1970-01-01
- C++ #define 1970-01-01
- C++定义类对象 1970-01-01
- C++输入/输出运算符重载 1970-01-01
- C语言访问数组元素 1970-01-01
- 初始化变量和赋值运算符 1970-01-01
- C++按值调用 1970-01-01
- 使用scanf()读取字符串 1970-01-01