+ 2
logical operators in C
hey whay the output is 1 ? int a=1; int b=1; int c= a || --b; printf ("%d",b); but in bellow code output is 0 ? int a=0; int b=1; int c= a || --b; printf ("%d",b);
12 Antworten
+ 7
All right apart from the edited question, I have to admit that the two results are different.
The reason is that the logical OR || return 1 when at least one of the operands is non-zero.
And if the first operand is not a 0, the second part is not going to be read.
+ 3
Search/look up "short circuit evaluation"
+ 1
You edited your question
In the original question you said the first code gives 0 and the second 1
But actually they are kind of the same code and the result is 0 for both.
+ 1
thank you i understood and excuse me beacuse of my bad English🙏🙏
0
You are lying 🙄
https://code.sololearn.com/cBA0RKQG007g/?ref=app
0
https://code.sololearn.com/cTDrMpxcK1s0/?ref=app
are you sure?
0
i say that the second code output is 0
0
for me is 0????
0
i tried it in visual studio
0
i edited it just after 5 second anyway excuse me but in this question outputs are 1 and 0 in order
right?
0
You are welcome 🤗🤗