Limits.h library is used to get the maximum and minimum limits of any datatypes. it means that the upper and the lower limits of any datatype can't be breaked. suppose the maximum limit of short in is 32767 so we can't store the value greater then this in short int datatype. let us see macros and its uses with how to use.
Macro | Value | Explaination |
CHAR_BIT | 8 | Shows the number of bits in one byte |
INT_MIN | -32767 | Minimum value of int datatype. |
UINT_MAX | 65535 | Maximum value of unsigned int datatype. |
SCHAR_MIN | -127 | Minimum value of char datatype. |
SCHAR_MAX | +127 | Maximum value of char datatype. |
UCHAR_MAX | 255 | Maximum value of unsigned char datatype. |
SHRT_MIN | -32767 | Minimum value of short int datatype. |
SHRT_MAX | +32767 | Maximum value of short int datatype. |
USHRT_MAX | 65535 | Maximum value of unsigned short int datatype. |
LONG_MIN | -2147483647 | Minimum value of long int datatype. |
Macro | +2147483647 | Maximum value of long int datatype. |
ULONG_MAX | +4294967295 | Maximum value of Unsigned long datatype. |
NOW LET US SEE EXAMPLE PROGRAM FOR THIS LIBRARY.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<limits.h>
main()
{
clrscr();
printf("The minimum value of CHAR is %d\n", CHAR_MIN);
printf("The maximum value of CHAR is %d\n", CHAR_MAX);
printf("The minimum value of SIGNED CHAR is %d\n", SCHAR_MIN);
printf("The maximum value of SIGNED CHAR is %d\n", SCHAR_MAX);
printf("The maximum value of UNSIGNED CHAR is %d\n", UCHAR_MAX);
printf("The minimum value of SHORT INT is %d\n", SHRT_MIN);
printf("The maximum value of SHORT INT is %d\n", SHRT_MAX);
printf("The minimum value of INT is %d\n", INT_MIN);
printf("The maximum value of INT is %d\n", INT_MAX);
printf("The minimum value of LONG is %ld\n", LONG_MIN);
printf("The maximum value of LONG is %ld\n", LONG_MAX);
printf("The number of bits in a byte is %d\n", CHAR_BIT);
getch();
return(0);
}