c++ cdi+示例
"or" is an inbuilt keyword that has been around since at least C++98. It is an alternative to || (Logical OR) operator and it mostly uses with the conditions.
“ or”是一个内置关键字,至少从C ++ 98起就存在。 它是||的替代方法 ( 逻辑OR )运算符,它通常与条件一起使用。
The or keyword returns 1 if the result of at least one operand is 1, and it returns 0 if all operands result is 0.
如果至少一个操作数的结果为1,则or关键字返回1;如果所有操作数的结果为0,则or关键字返回0。
Syntax:
句法:
operand_1 or operand_2;
Here, operand_1 and operand_2 are the operands.
在这里,操作数_1和操作数_2是操作数。
Example:
例:
Input:
a = 10;
b = 20;
result = (a==10 or b==30);
Output:
result = 1
演示使用“ or”关键字的C ++示例 (C++ example to demonstrate the use of "or" keyword)
// C++ example to demonstrate the use of
// 'or' operator.
#include <iostream>
using namespace std;
int main()
{
int num = 20;
if (num >= 10 or num <= 50)
cout << "true\n";
else
cout << "false\n";
if (num >= 20 or num <= 50)
cout << "true\n";
else
cout << "false\n";
if (num > 50 or num <= 100)
cout << "true\n";
else
cout << "false\n";
return 0;
}
Output:
输出:
true
true
true
翻译自: https://www.includehelp.com/cpp-tutorial/or-keyword-with-example.aspx
c++ cdi+示例