char 类型的常数
C ++ CHAR_MAX宏常量 (C++ CHAR_MAX macro constant)
CHAR_MAX constant is a macro constant which is defied in climits header, it is used to get the maximum value of a char object, it returns the maximum value that a char object can store, which is either 127 (SCHAR_MAX) or 255 (UCHAR_MAX).
CHAR_MAX常量是在climits标头中定义的宏常量,用于获取char对象的最大值,它返回char对象可以存储的最大值,即127( SCHAR_MAX )或255( UCHAR_MAX ) 。
Note:
注意:
The actual value depends on the compiler architecture or library implementation.
实际值取决于编译器体系结构或库实现。
We can also use <limits.h> header file instead of <climits> header as CHAR_MAX constant is defined in both of the libraries.
我们也可以使用<limits.h>头文件而不是<climits>头文件,因为在两个库中都定义了CHAR_MAX常量 。
Syntax of CHAR_MAX constant:
CHAR_MAX常数的语法:
CHAR_MAX
Example:
例:
Constant call:
cout << CHAR_MAX;
Output:
127
C ++代码演示带有climits标头的CHAR_MAX常量示例 (C++ code to demonstrate example of CHAR_MAX constant with climits header)
// C++ code to demonstrate example of
// CHAR_MAX constant with climits header
#include<iostream>
#include<climits>
using namespace std;
int main()
{
//prinitng the value of CHAR_MAX
cout<<"CHAR_MAX: "<<CHAR_MAX<<endl;
return 0;
}
Output
输出量
CHAR_MAX: 127
C ++代码演示带有limits.h头文件的CHAR_MAX常量示例 (C++ code to demonstrate example of CHAR_MAX constant with limits.h header file)
// C++ code to demonstrate example of
// CHAR_MAX constant with <limits.h> header file
#include<iostream>
#include<limits.h>
using namespace std;
int main()
{
//prinitng the value of CHAR_MAX
cout<<"CHAR_MAX: "<<CHAR_MAX<<endl;
return 0;
}
Output
输出量
CHAR_MAX: 127
翻译自: https://www.includehelp.com/cpp-tutorial/CHAR_MAX-constant-with-example.aspx
char 类型的常数