limits.h in C

Previous
Next

limits.h:

  • It is pre-defined header file.
  • This header file contains set of variables
    • INT_MIN
    • INT_MAX
    • UINT_MIN
    • SHRT_MIN
    • SHRT_MAX
    • USHART_MAX
    • SCHAR_MIN
    • SCHAR_MAX
    • UCHAR_MAX
  • These variables holding some values.
  • These variables represent the minimum and maximum limits of each data type.

Displaying signed character limits:

#include <stdio.h>
#include <limits.h>
int main()
{
	printf("signed char min val : %d \n", SCHAR_MIN);
	printf("signed char max val : %d \n", SCHAR_MAX);
	return 0;
}

Output:
signed char min val : -128
signed char max val : 127

Displaying unsigned character limits:

  • Limits.h header file is not providing the variable to print minimum value of unsigned type.
  • For example
    • UCHAR_MIN
    • USHRT_MIN
    • UINT_MIN
    • ULONG_MIN
  • The reason – minimum value of unsigned type starts with 0 ; Hence we can remember easily.
  • It is providing only maximum limit.
#include <stdio.h>
#include <limits.h>
int main()
{
	/* printf("unsigned char min val : %d \n", UCHAR_MIN);  --> Error : */  
	printf("unsigned char max val : %d \n", UCHAR_MAX);
	return 0;
}

Output:
unsigned char max val : 255
Previous
Next

Add Comment

Courses Enquiry Form