C++ 'or' Keyword with Example

C++ | 'or' keyword: Here, we are going to learn about the 'or' keyword which is an alternative to Logical OR operator.
Submitted by IncludeHelp, on May 16, 2020

"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.

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.

Syntax:

    operand_1 or operand_2;

Here, operand_1 and operand_2 are the operands.

Example:

    Input:
    a = 10;
    b = 20;
    
    result = (a==10 or b==30);

    Output:
    result = 1

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






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.