+ 15

Can somebody explain about && and || operator.??

sometimes i get confused ..how it works properly && and || operator..

14th Oct 2018, 12:52 AM
Shyam Krishnan K
Shyam Krishnan K - avatar
40 Antworten
+ 11
&& is Logial AND. True only if all operands are true. example - If c = 5 and d = 2 then, expression ((c == 5) && (d > 5))equals to 0. 👈 its false || Logical OR. True only if either one operand is true. example - If c = 5 and d = 2 then, expression ((c == 5) || (d > 5))equals to 1.👈its true.
15th Oct 2018, 7:27 AM
Vishnu
Vishnu - avatar
+ 10
&& means and. || means or. Just like in English. && checks if the expression on the left and right is true. || checks if either the expression on left or right is true. 4>0 && 4<5 will return true. 4>0 && 4<4 will return false. 50>5 || 9!=9 will return true. 50==5 || 0>1 will return false.
14th Oct 2018, 1:02 AM
qwerty
qwerty - avatar
+ 10
tq i got it then how does this works.. int a=1; int b =0; cout<<(!(a||b)&&(!b); what is the output of this and how.
14th Oct 2018, 1:15 AM
Shyam Krishnan K
Shyam Krishnan K - avatar
+ 9
Both are the Logical operator. & logical AND (Both should be correct). || logical OR (If only one is correct then also it'll print True). Think about this Example: let Day, Night, Sun, Moon //now map all the values eg. Day && Sun == True //both comes together Night && Moon == True //likewise Day || Night == True //true coz either Day or Night Sun || Moon == True //likewise But Not these things'll happen concurrently eg. the result will False. Day && Moon Night && Sun
14th Oct 2018, 3:29 AM
Sin Cos Ø
Sin Cos Ø - avatar
+ 7
no Sh5am (1||0) becomes true and then !(1||0) becomes false
14th Oct 2018, 5:04 AM
Yamini Jalibili
Yamini Jalibili - avatar
+ 7
now that you understand the difference between && and || you should know about & and | operators. heres a code to understand the difference between && and &. https://code.sololearn.com/cFMT3b4TWgCy/?ref=app
14th Oct 2018, 11:50 AM
voja
voja - avatar
+ 6
In C++, 0 means false and anything other than 0 means true. !(a||b) or !(1||0) will be false. !b or !0 is true. false&&true will return false or 0.
14th Oct 2018, 1:39 AM
qwerty
qwerty - avatar
+ 6
еге
20th Oct 2018, 11:54 AM
Proger/com
Proger/com - avatar
+ 5
bro how does !(1||0) becomes false its true know..?
14th Oct 2018, 2:22 AM
Shyam Krishnan K
Shyam Krishnan K - avatar
+ 5
1||0 is true ! (1||0) is false
14th Oct 2018, 5:40 AM
√!π😊d
√!π😊d - avatar
+ 4
how its true vinu. can u explain it da
14th Oct 2018, 5:25 AM
Shyam Krishnan K
Shyam Krishnan K - avatar
+ 4
tqsm qwerty...
14th Oct 2018, 5:28 AM
Shyam Krishnan K
Shyam Krishnan K - avatar
+ 4
1||1=1 1||0=1 0||1=1 0||0=0 or operator performes addition operation da + so either is true it bcms true
14th Oct 2018, 5:29 AM
√!π😊d
√!π😊d - avatar
+ 4
vinu what will b the ouput according to u da?
14th Oct 2018, 5:36 AM
Shyam Krishnan K
Shyam Krishnan K - avatar
+ 4
Hi, this is my first answer and will be based of my basic understanding of this concept. && is a boolean operator, it executes code only when both conditions are met. || is a OR operator meaning it will execute the code if either one of the conditions are met. ——————— BASIC EXAMPLE: #include <iostream> using namespace std; int main() { int rank = 2; int age = 16; if (rank <= 10 || age >= 18 ){ cout << "You Qualify for the olympics" << endl; } return 0; } //OUTPUTS: You Qualify for the olympics
14th Oct 2018, 8:10 AM
Michael
Michael  - avatar
+ 3
no shyam it becomes true
14th Oct 2018, 4:49 AM
√!π😊d
√!π😊d - avatar
+ 3
tq saransh kumar chauhan ..
14th Oct 2018, 5:27 AM
Shyam Krishnan K
Shyam Krishnan K - avatar
+ 3
&& defines and operator when all conditions are true... || defines or operator when one or two or more conditions satisfied
15th Oct 2018, 8:00 AM
Yeshwanth Manikanta
Yeshwanth Manikanta - avatar
+ 3
|| and && first || means OR condition any one of the condition is TRUE then its TRUE this opertation has following possible true || true= True true || false= True false || true= True false || false= False Second && means AND condition any one of the condition is FALSE then its FALSE, All the condition must be TRUE then TRUE this opertation has following possible true && true= True true && false= False false && true= False false && false= False
15th Oct 2018, 2:41 PM
yeshi Tsering
yeshi Tsering - avatar
+ 3
In Java: && is called the And Operator || is called the Or Operator The And Operator checks that both operands are true and then the condition is deemed true. Whilst with the Or Operator, only 1 operand needs to be true, then the condition becomes true. e.g. AND Operator An applicant needs to be older than 18 AND have paid a minimum of $1000 deposit for the condition to be met and therefore the application being approved/deemed successful for the Applicants tertiary studies: int age=22 int deposit=2200 if(age>18 && deposit>1000){ System.out.prinln("Approved"); } //Output is Approved as both conditions are met e.g. OR Operator An applicant should be to be older than 18 OR they must have paid the minimum of $1000 deposit for the condition to be met and therefore the application being approved/deemed successful for the Applicants tertiary studies: int age=17 int deposit=2200 if(age>18 || deposit>1000){ System.out.prinln("Approved"); } //Output is Approved as the deposit condition is true
15th Oct 2018, 3:01 PM
Von Jones
Von Jones - avatar