English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The header file "limits.h" exists in C language, while <climits> exists in C ++The language exists. Several macros are defined in these header files. The limits specify the values that a variable cannot store beyond the limits.
Some macros in the "limits.h" or <climits> header file are as follows
CHAR_BIT | LONG_MIN | LONG_MAX | CHAR_MIN | CHAR_MAX |
INT_MIN | INT_MAX | SHRT_MIN | SHRT_MAX | ULONG_MAX |
This is C ++Example of <climits> in the language,
#include<iostream> #include <bits/stdc++.h> #include<climits> 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++) { s.push(x%2); x = x/2; } cout << "The number of bits in a byte : " << CHAR_BIT << endl; for (int i=1; i <= a; i++) { cout << s.top(); s.pop(); if (i % CHAR_BIT == 0) cout << " "; } cout << "\n\nThe minimum value of short int :" << SHRT_MIN; return 0; }
Output Result
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 from <climits> are represented. One is CHAR_BIT, and the other is SHRT_MIN. CHAR_BIT defines the number of bits in a char, while SHRT_MIN defines the minimum value of short int.
int x = 28; int a = CHAR_BIT;*sizeof(x); ... cout << "\n\nThe minimum value of short int :" << SHRT_MIN;