logical operators in C | Sololearn: Learn to code for FREE!


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);

11/25/2020 7:56:13 PM

Javad Besharati

12 Answers

New Answer


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.


Search/look up "short circuit evaluation"


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.


thank you i understood and excuse me beacuse of my bad English🙏🙏


You are lying 🙄 https://code.sololearn.com/cBA0RKQG007g/?ref=app


https://code.sololearn.com/cTDrMpxcK1s0/?ref=app are you sure?


i say that the second code output is 0


for me is 0????


i tried it in visual studio


i edited it just after 5 second anyway excuse me but in this question outputs are 1 and 0 in order right?


You are welcome 🤗🤗