+ 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

27th Dec 2018, 4:00 AM
Abdul Rahman Khan
Abdul Rahman Khan - avatar
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"
27th Dec 2018, 4:38 AM
Calviղ
Calviղ - avatar
+ 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.
27th Dec 2018, 4:30 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
Precedence overrides left-to-right association Gordon
27th Dec 2018, 7:07 AM
Calviղ
Calviղ - avatar
+ 2
Both version of codes are answered above😊
27th Dec 2018, 4:48 AM
MsJ
MsJ - avatar
+ 1
Gordon && has higher precedence than || ! operator has even more higher
27th Dec 2018, 5:53 AM
Calviղ
Calviղ - avatar
+ 1
Thanks to all
27th Dec 2018, 6:48 AM
Abdul Rahman Khan
Abdul Rahman Khan - avatar
0
If there is no parenthesis what will be answer
27th Dec 2018, 4:46 AM
Abdul Rahman Khan
Abdul Rahman Khan - avatar
0
How
27th Dec 2018, 4:49 AM
Abdul Rahman Khan
Abdul Rahman Khan - avatar
0
true && 1 || 0 Is (true && 1) || 0 Or true && (1||0) ?
27th Dec 2018, 5:49 AM
Gordon
Gordon - avatar
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)"?
27th Dec 2018, 5:56 AM
Gordon
Gordon - avatar
0
Sequence of precedence, from high to low: ! < && ||
27th Dec 2018, 5:57 AM
Calviղ
Calviղ - avatar
0
true && 1 || 0 is equals to (true && 1) || 0
27th Dec 2018, 5:59 AM
Calviղ
Calviղ - avatar
0
Thanks for the reference website. I noticed the associativity of Left-to-right, then that explains the above code playground result.
27th Dec 2018, 6:42 AM
Gordon
Gordon - avatar