+ 2
#include <stdio.h> int main() { int a=8, b=0,c=0; if(!a<10&& !b||c) printf("Rahman"); elae printf("abdul"); return 0; }
Explain How it work
15 Respostas
+ 1
#include <stdio.h>
int main() {
int a=8, b=0,c=0;
if(!a<10&& !b||c)
printf("Rahman");
else printf("abdul");
return 0;
}
if(!a<10&& !b||c)
Is equals to
if( ((!a) <10) && (!b) || c)
!a = !8 = 0
!b = 1
So
if( (0<10) && 1 || 0)
Is equals to
if( true && 1 || 0)
Is equals to True
It should print "Rahman"
+ 4
Abdul Rahman Khan firstly your code has some type and missing parenthesis the correct code should be like this
#include <stdio.h>
int main() {
int a=8, b=0,c=0;
if(!(a<10)&& !(b||c))
printf("Rahman");
else
printf("abdul");
return 0;
}
Now how "abdul " is printed? Because
8<10= true which is 1 in boolean the not operation is performed then so 1 become 0
0||0 gives 0 then not operation make it 1
Now 0 && 1 which evaluated as 0 because and(&&) is multiplication and or (||) is sum so it gives 0 and else part is evaluated and printed.
+ 3
Precedence overrides left-to-right association Gordon
+ 2
Both version of codes are answered above😊
+ 1
Gordon && has higher precedence than ||
! operator has even more higher
+ 1
Thanks to all
0
If there is no parenthesis what will be answer
0
How
0
true && 1 || 0
Is
(true && 1) || 0
Or
true && (1||0)
?
0
That means
"a and b or c" is "(a and b) or c",
and
"a or b and c" is "a or (b and c)"?
0
Sequence of precedence, from high to low:
!
<
&&
||
0
true && 1 || 0 is equals to (true && 1) || 0
0
Thanks for the reference website.
I noticed the associativity of Left-to-right, then that explains the above code playground result.