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
trueif at least one operand evaluates totrue. - It returns
falseonly when both operands evaluate tofalse. (marks >= 90)checks whether the marks satisfy the required condition.sports_quotarepresents another condition that can independently satisfy the eligibility criteria.- The expression
(marks >= 90) || sports_quotaevaluates totrueif either condition is satisfied. - By default,
std::coutdisplays Boolean values as1fortrueand0forfalse. return 0;terminates the program successfully.