• Home
  • 3.11 Logical OR Operator (||)

3.11 Logical OR Operator (||)

View Categories

3.11 Logical OR Operator (||)

< 1 min read

Table of Contents

The logical OR operator (||) combines two Boolean expressions and returns true if at least one of the expressions evaluates to true. The result is false only when both expressions evaluate to false.

The logical OR operator is commonly used when a program should perform an action if any one of multiple conditions is satisfied.

Source Code #

#include <iostream>

int main()
{
    int marks = 85;
    bool sports_quota = false;

    bool eligible = (marks >= 90) || sports_quota;

    std::cout << "Eligible: " << eligible << '\n';

    return 0;
}

Output #

Eligible: 0

Explanation #

  • The logical OR operator (||) combines two Boolean expressions.
  • It returns true if at least one operand evaluates to true.
  • It returns false only when both operands evaluate to false.
  • (marks >= 90) checks whether the marks satisfy the required condition.
  • sports_quota represents another condition that can independently satisfy the eligibility criteria.
  • The expression (marks >= 90) || sports_quota evaluates to true if either condition is satisfied.
  • By default, std::cout displays Boolean values as 1 for true and 0 for false.
  • return 0; terminates the program successfully.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *