C++ Logical Operators
Logical Operators use to provide logic in our program and we use them to compare between different values like
Greater than >
Less than <
Equal =
NotEqual !=
We can use them between two operator at one time in one condition like Greater and Equal >=.
while using >= and <= it'll execute statement if one of them is true either > or = we'll cover this below by showing example
Covering core programming of C++ and while practicing basics we work with if else conditional statements , for loop , while loop , do while loop. we use them to perform different tasks it is depending on our needs.
Greater than >
Less than <
Equal =
NotEqual !=
We can use them between two operator at one time in one condition like Greater and Equal >=.
while using >= and <= it'll execute statement if one of them is true either > or = we'll cover this below by showing example
Covering core programming of C++ and while practicing basics we work with if else conditional statements , for loop , while loop , do while loop. we use them to perform different tasks it is depending on our needs.
Example Program of Logical operators
Example
Logical Operators
- #include <iostream>
- using namespace std;
- int main( ){
- int x = 5 ; // Assignment Operator use to assign value
- int y = 10;
- if ( x > y ){
- cout << " X > Y " << x << " > " << y << endl ;
- }
- if ( x == y ){
- cout << " X = Y " << x << " = " << y << endl ;
- }
- if ( x < y ){ //execute because x is less than y
- cout << " X < Y " << x << " < " << y << endl ;
- }
- if ( x != y ){ // execute because x is Not equal !
- cout << " X != Y " << x << " != " << y << endl ;
- }
- if ( x >= y ){
- cout << " X >= Y " << x << " >= " << y << endl ;
- }
- if ( x <= y ){ // execute because < is true
- cout << " X <= Y " << x << " <= " << y << endl ;
- }
- return 0;
- }
Comments
Post a Comment