C Library - < limits.h >

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 cannot store any value beyond these limits, for example an unsigned character can store up to 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_BIT8Defines the number of bits in a byte.
SCHAR_MIN-128Defines the minimum value for a signed char.
SCHAR_MAX+127Defines the maximum value for a signed char.
UCHAR_MAX255Defines the maximum value for an unsigned char.
CHAR_MIN-128Defines the minimum value for type char and its value will be equal to SCHAR_MIN if char represents negative values, otherwise zero.
CHAR_MAX+127Defines the value for type char and its value will be equal to SCHAR_MAX if char represents negative values, otherwise UCHAR_MAX.
MB_LEN_MAX16Defines the maximum number of bytes in a multi-byte character.
SHRT_MIN-32768Defines the minimum value for a short int.
SHRT_MAX+32767Defines the maximum value for a short int.
USHRT_MAX65535Defines the maximum value for an unsigned short int.
INT_MIN-2147483648Defines the minimum value for an int.
INT_MAX+2147483647Defines the maximum value for an int.
UINT_MAX4294967295Defines the maximum value for an unsigned int.
LONG_MIN-9223372036854775808Defines the minimum value for a long int.
LONG_MAX+9223372036854775807Defines the maximum value for a long int.
ULONG_MAX18446744073709551615Defines the maximum value for an unsigned long int.

Example

The following example shows the usage of few of the constants defined in limits.h file.
#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);
}
Let us compile and run the above program that will produce the following result −
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 = -2147483648                                      
The maximum value of INT = 2147483647                                       
The minimum value of CHAR = -128                                            
The maximum value of CHAR = 127                                             
The minimum value of LONG = -9223372036854775808                            
The maximum value of LONG = 9223372036854775807

Contact

Talk to us

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores iusto fugit esse soluta quae debitis quibusdam harum voluptatem, maxime, aliquam sequi. Tempora ipsum magni unde velit corporis fuga, necessitatibus blanditiis.

Address:

৪৭/ দক্ষিণ বেগুনবাড়ি তেজগাঁও শিল্প এলাকা ঢাকা ১২০৮

Work Time:

সোমবার - শুক্রবার থেকে সকাল 9 টা থেকে বিকাল 5 টা

Phone:

+88 019 4145 2627