+ 4
Why this code outputs "0" in C language?
printf("%d", !(1 || 0 && !1));
2 Antworten
+ 5
Win Htay
I am not sure but it's because of precedence. As precedence of not (!) Operator is more and it works from right to left so first it will make last 1 to 0 than in next step the more precedence is of and(&&) operator so that perform left to right so 0&&0 will equate to 0. After that 1||0 make 1 as thr result after that again doing not operation it will make that 1 to 0 and print it.
if I'm wrong anyone can correct me but it should work like this.
+ 5
code executes from left to right in the bracket also.
it executes as this:-
1. printf("%d", !(1 || 0 && !1));
2. printf("%d", !(1 || 0 && 0));
3. printf("%d", !(1 || 1));
4. printf("%d", !(1));
5. printf("%d", !1);
6. printf("%d", 0);
output 0
hence there is output of 0.
Hope this will help you.
Happy Coding.