0
I can't understand why the output is so?
let I=0,j=-1,k=3,n=2 m=I++||j++&&k++||++n&&--k; after executing this statement the value of I,j, k,n is 1,0,4,2 respectively but executing each segment separately the values of I,j, k,n is 1,0,3,3 respectively,,,,you may refer the output of my code<increment><increment2>
4 Antworten
+ 2
I find answer.
"&&" and "||" operates on boolean operands only.
For "&&" :
It evaluates its first operand.
If the result isfalse, it returns false. Otherwise, it evaluates and returns the results of the second operand.
Note that, if evaluating the second operand would hypothetically have no side effects, the results are identical to the logical conjunction performed by the &operator. This is an example of Short Circuit Evaluation.
And about your code.
1. first condition is "l++" it's return "false".
now l=1
we have "false||j++"
2. than "j++" return "true".
now j=0
3. thats (l++||j++) equal to false||true and return true
4. next we have: "true&&k++"
5. k++ return true.
now k=4
6. now "true&&true" return true.
7. next we have "true||++n"
but compiller not evaluated "++n" becuse result of "true||anything" return true
Thats m=true and l,j,k,n = 1,0,4,2
+ 1
l++ return 0+1=1
j++ return -1+1=0
k++, then --k return 3-1+1=3
n++ return 2+1=3
0
but the output is 1,0,4,2 for the above statement
0
thank you