简介limits.h 头文件决定了各种变量类型的各种属性。定义在该头文件中的宏限制了各种变量类型(比如 char、int 和 long)的值。 这些限制指定了变量不能存储任何超出这些限制的值,例如一个无符号可以存储的最大值是 255。 库宏下面的值是特定实现的,且是通过 #define 指令来定义的,这些值都不得低于下边所给出的值。
实例下面的实例演示了 limit.h 文件中定义的一些常量的使用。 #include <stdio.h> #include <limits.h> int main() { printf("The number of bits in a byte %d\n", CHAR_BIT); printf("The minimum value of SIGNED CHAR = %d\n", SCHAR_MIN); printf("The maximum value of SIGNED CHAR = %d\n", SCHAR_MAX); printf("The maximum value of UNSIGNED CHAR = %d\n", UCHAR_MAX); printf("The minimum value of SHORT INT = %d\n", SHRT_MIN); printf("The maximum value of SHORT INT = %d\n", SHRT_MAX); printf("The minimum value of INT = %d\n", INT_MIN); printf("The maximum value of INT = %d\n", INT_MAX); printf("The minimum value of CHAR = %d\n", CHAR_MIN); printf("The maximum value of CHAR = %d\n", CHAR_MAX); printf("The minimum value of LONG = %ld\n", LONG_MIN); printf("The maximum value of LONG = %ld\n", LONG_MAX); return(0); } 让我们编译和运行上面的程序,这将产生下列结果: 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 |
Archiver|手机版|小黑屋|小白教程 ( 粤ICP备20019910号 )
GMT+8, 2024-11-24 12:02 , Processed in 0.013717 second(s), 18 queries .
Powered by Discuz! X3.4
© 2001-2017 Comsenz Inc. Template By 【未来科技】【 www.wekei.cn 】