Search
 
SCRIPT & CODE EXAMPLE
 

C

logical operator

Or operator : || 
And operator : &&
Comment

logical operators

Please thank, like, follow and improve
logical operators are used to test multiple conditions i.e. combine two or more conditions
They are:
and - &
or - |
not - !
and operators return true if and only if both operators are true. 
or operators return true if at least one operator is true.
not operator inverts a situation or condition: if true it turns it false and vice-versa.
Comment

logical operators

Logical Operators: 
They are used to combine two or more conditions/constraints or to complement 
the evaluation of the original condition under consideration. They are 
described below: 
 

Logical AND operator: The ‘&&’ operator returns true when both the conditions 
under consideration are satisfied. Otherwise it returns false. For example, a
&& b returns true when both a and b are true (i.e. non-zero).

Logical OR operator: The ‘||’ operator returns true even if one (or both) of
the conditions under consideration is satisfied. Otherwise it returns false. 
For example, a || b returns true if one of a or b or both are true 
(i.e. non-zero). Of course, it returns true when both a and b are true.

Logical NOT operator: The ‘!’ operator returns true the condition in 
consideration is not satisfied. Otherwise it returns false. For example, 
!a returns true if a is false, i.e. when a=0.
Comment

Logical Operators

#include <iostream>
using namespace std;

int main() {
    bool result;

    result = (3 != 5) && (3 < 5);     // true
    cout << "(3 != 5) && (3 < 5) is " << result << endl;

    result = (3 == 5) && (3 < 5);    // false
    cout << "(3 == 5) && (3 < 5) is " << result << endl;

    result = (3 == 5) && (3 > 5);    // false
    cout << "(3 == 5) && (3 > 5) is " << result << endl;

    result = (3 != 5) || (3 < 5);    // true
    cout << "(3 != 5) || (3 < 5) is " << result << endl;

    result = (3 != 5) || (3 > 5);    // true
    cout << "(3 != 5) || (3 > 5) is " << result << endl;

    result = (3 == 5) || (3 > 5);    // false
    cout << "(3 == 5) || (3 > 5) is " << result << endl;

    result = !(5 == 2);    // true
    cout << "!(5 == 2) is " << result << endl;

    result = !(5 == 5);    // false
    cout << "!(5 == 5) is " << result << endl;

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: node in c 
C :: what is the last character of a string in c 
C :: c calling a function 
C :: c arrays and pointers 
C :: what is console in sublime text 
C :: c malloc 
C :: create syscall 
C :: printing words lemgthwise in c 
C :: bcd to char c 
C :: android studio sdkmanager always accept 
C :: c program for calculating product of array 
C :: how to change the smartart style to 3D polished in powerpoint 
C :: change base int in c 
C :: c to assembly online compiler 
C :: bool print variable in c 
C :: how to make C program blink on screen 
C :: Print Characters 
C :: command line arguments to copy paste in c 
C :: c disable struct padding 
C :: Algorithm that flips sentences and numbers 
C :: get flag status c code 
C :: Sum of upper & lower triangles elements 
C :: how to devowel string in c program 
C :: opération bit à bit c 
C :: sdl close ev 
C :: change variable type in c 
C :: merge sort in c 
C :: c triangle check if triangle is 90 degrees 
Dart :: flutter transparent appbar 
Dart :: How to center AlertDialog FlatButton in Flutter 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =