zoukankan      html  css  js  c++  java
  • C Library

    Introduction

    The limits.h header determines various properties of the various variable types. The macros defined in this header limits the values of various variable types like char, int and long.

    These limits specify that a variable can not store any value beyond these limits, for example an unsigned character can store upto a maximum value of 255.

    Library Macros

    The following values are implementation-specific and defined with the #define directive, but these values may not be any lower than what is given here.

    MacroValueDescription
    CHAR_BIT 8 Defines the number of bits in a byte.
    SCHAR_MIN -128 Defines the minimum value for a signed char.
    SCHAR_MAX 127 Defines the maximum value for a signed char.
    UCHAR_MAX 255 Defines the maximum value for an unsigned char.
    CHAR_MIN 0 Defines the minimum value for type char and its value will be equal to SCHAR_MIN if char represents negative values otherwise zero.
    CHAR_MAX 127 Defines the value for type char and its value will be equal to SCHAR_MAX if char represents negative values otherwise UCHAR_MAX
    MB_LEN_MAX 1 Defines the maximum number of bytes in a multibyte character.
    SHRT_MIN -32768 Defines the minimum value for a short int.
    SHRT_MAX +32767 Defines the maximum value for a short int.
    USHRT_MAX 65535 Defines the maximum value for an unsigned short int.
    INT_MIN -32768 Defines the minimum value for an int.
    INT_MAX +32767 Defines the maximum value for an int.
    UINT_MAX 65535 Defines the maximum value for an unsigned int.
    LONG_MIN -2147483648 Defines the minimum value for a long int.
    LONG_MAX +2147483647 Defines the maximum value for a long int.
    ULONG_MAX 4294967295 Defines the maximum value for an unsigned long int.

    Example

    The following example shows the usage of few of the constants defined in limit.h file.

    #include <stdio.h>
    #include <limits.h>
    
    int main()
    {
    
       printf("The number of bits in a byte %d
    ", CHAR_BIT);
    
       printf("The minimum value of SIGNED CHAR = %d
    ", SCHAR_MIN);
       printf("The maximum value of SIGNED CHAR = %d
    ", SCHAR_MAX);
       printf("The maximum value of UNSIGNED CHAR = %d
    ", UCHAR_MAX);
    
       printf("The minimum value of SHORT INT = %d
    ", SHRT_MIN);
       printf("The maximum value of SHORT INT = %d
    ", SHRT_MAX); 
    
       printf("The minimum value of INT = %d
    ", INT_MIN);
       printf("The maximum value of INT = %d
    ", INT_MAX);
    
       printf("The minimum value of CHAR = %d
    ", CHAR_MIN);
       printf("The maximum value of CHAR = %d
    ", CHAR_MAX);
    
       printf("The minimum value of LONG = %ld
    ", LONG_MIN);
       printf("The maximum value of LONG = %ld
    ", LONG_MAX);
      
       return(0);
    }

    Let us compile and run the above program, this will produce the following result:

    The number of bits in a byte 8
    The minimum value of SIGNED CHAR = -128
    The maximum value of SIGNED CHAR = 127
    The maximum value of UNSIGNED CHAR = 255
    The minimum value of SHORT INT = -32768
    The maximum value of SHORT INT = 32767
    The minimum value of INT = -32768
    The maximum value of INT = 32767
    The minimum value of CHAR = -128
    The maximum value of CHAR = 127
    The minimum value of LONG = -2147483648
    The maximum value of LONG = 2147483647
    
  • 相关阅读:
    springboot集成mockito与powermock
    不一样的go语言-玩转语法之二
    不一样的go语言-玩转语法之一
    不一样的go语言-athens源码概览
    不一样的go语言-athens私仓安装
    不一样的go语言-构建系统与构件系统
    不一样的go语言-error
    不一样的go语言-gopher
    jssip中文开发文档(完整版)
    echarts属性的设置(完整大全)
  • 原文地址:https://www.cnblogs.com/yyxayz/p/4060825.html
Copyright © 2011-2022 走看看