c语言的极限值的问题

 时间:2026-02-16 03:46:34

1、类型                    下限                      上限

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 

无符号下限是0      U CHAR_MAX   USHRT_MAX   U INT_MAX   ULONG_MAX   ULLONG_MAX 

例如 int number = INT_MAX ;

c语言的极限值的问题

2、<float.h>头文件定义了表示浮点数的符号

类型                    下限                      上限

float                   FLT_MIN                 FLT_MAX

double                 DBL_MAX              DBL_MAX

long double           LDBL_MIN          LDBL_MAX

c语言的极限值的问题

3、例子:

/* Program 2.11 Finding the limits  */

#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",

                                                  CHAR_MIN, CHAR_MAX);

  printf("\nVariables of type unsigned char store values from 0 to %u",

                                                           UCHAR_MAX);

  printf("\nVariables of type short store values from %d to %d",

                                                 SHRT_MIN, SHRT_MAX);

  printf("\nVariables of type unsigned short store values from 0 to %u",

                                                         USHRT_MAX);

  printf("\nVariables of type int store values from %d to %d", INT_MIN, INT_MAX);

  printf("\nVariables of type unsigned int store values from 0 to %u", UINT_MAX);

  printf("\nVariables of type long store values from %ld to %ld",

                                               LONG_MIN, LONG_MAX);

  printf("\nVariables of type unsigned long store values from 0 to %lu",

                                                        ULONG_MAX);

  printf("\nVariables of type long long store values from %lld to %lld",

                                               LLONG_MIN, LLONG_MAX);

  printf("\nVariables of type unsigned long long store values from 0 to %llu",

                                                        ULLONG_MAX);

  printf("\n\nThe size of the smallest non-zero value of type float is %.3e",

                                                         FLT_MIN);

  printf("\nThe size of the largest value of type float is %.3e", FLT_MAX);

  printf("\nThe size of the smallest non-zero value of type double is %.3e",

                                                        DBL_MIN);

  printf("\nThe size of the largest value of type double is %.3e", DBL_MAX);

  printf("\nThe size of the smallest non-zero value of type long double is %.3Le",

                                                       LDBL_MIN);

  printf("\nThe size of the largest value of type long double is %.3Le\n",

                                                        LDBL_MAX);

  printf("\nVariables of type float provide %u decimal digits precision.",

                                                           FLT_DIG);

  printf("\nVariables of type double provide %u decimal digits precision.",

                                                           DBL_DIG);

  printf("\nVariables of type long double provide %u decimal digits precision.",

                                                         LDBL_DIG);

  return 0;

}

摘自《C语言入门经典》第4版

  • C#如何通过Directory类移动(剪切)文件夹
  • 怎么用VBA代码设置幼圆字体
  • Python 3.8安装方法
  • 《名侦探柯南》里京极真在爱奇艺里出场集数,最重要的是怪盗基德vs京极真的集数
  • 印象笔记激活码怎么兑换
  • 热门搜索
    海南自助旅游 长春大学旅游学院吧 旅游网络营销 旅游北京 石家庄旅游局 澳门旅游攻略一日游 去厦门旅游攻略 台湾 旅游 那曲旅游 中国旅游人才网