C / C ++中的(limits.h)
头文件“limits.h”以C语言存在,而<climits>以C++语言存在。在这些头文件中定义了几个宏。限制指定变量不能存储超出限制的值。
“limits.h”或<climits>头文件中的一些宏如下
这是C++语言中<climits>的示例,
示例
#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;
}输出结果
The number is : 28 The number of bits in a byte : 8 00000000 00000000 00000000 00011100 The minimum value of short int :-32768
在上面的程序中,表示了<climits>的两个宏。一个是CHAR_BIT,另一个是SHRT_MIN。CHAR_BIT定义char中的位数,而SHRT_MIN定义shortint的最小值。
int x = 28; int a = CHAR_BIT*sizeof(x); …. cout << "\n\nThe minimum value of short int :" << SHRT_MIN;
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下