<climits> (limits.h) in C/C++

CC++Server Side Programming

The header files “limits.h” exists in C language while <climits> in C++ language. Several macros are defined in these header files. The limits specify that variable cannot store values beyond the limits.

Some macros in “limits.h” or <climits> header file are as follows


Here is an example of <climits> in C++ language,


 Live Demo

#include <bits/stdc++.h>
using namespace std;
int main() {
   int x = 28;
   int a = CHAR_BIT*sizeof(x);
   stack<bool> s;
   cout << "The number is : " << x << endl;
   for (int i=1; i<=a; i++) {
      x = x/2;
   cout << "The number of bits in a byte : " << CHAR_BIT << endl;
   for (int i=1; i<=a; i++) {
      cout << s.top();
      if (i % CHAR_BIT == 0)
      cout << " ";
   cout << "\n\nThe minimum value of short int :" << SHRT_MIN;
   return 0;


The number is : 28
The number of bits in a byte : 8
00000000 00000000 00000000 00011100

The minimum value of short int :-32768

In the above program, two macros of <climits> are represented. One is CHAR_BIT and another is SHRT_MIN. CHAR_BIT defines the number of bits in char and SHRT_MIN defines the minimum value for short int.

int x = 28;
int a = CHAR_BIT*sizeof(x);
cout << "\n\nThe minimum value of short int :" << SHRT_MIN;
Updated on 26-Jun-2020 08:16:40