+ 15
Can somebody explain about && and || operator.??
sometimes i get confused ..how it works properly && and || operator..
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.
+ 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.
+ 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.
+ 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
+ 7
no Sh5am
(1||0) becomes true and then
!(1||0) becomes false
+ 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
+ 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.
+ 6
еге
+ 5
bro how does !(1||0) becomes false its true know..?
+ 5
1||0 is true
! (1||0) is false
+ 4
how its true vinu. can u explain it da
+ 4
tqsm qwerty...
+ 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
+ 4
vinu what will b the ouput according to u da?
+ 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
+ 3
no shyam it becomes true
+ 3
tq saransh kumar chauhan ..
+ 3
&& defines and operator when all conditions are true...
|| defines or operator when one or two or more conditions satisfied
+ 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
+ 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