Hello Dear.. This Age Old question is Still Haunting Ppls.. In fact this ain't a question at all.. this Should be known while we start writing first of the C/C++ programming..
Well.. Just to make some ppls Life easier here it goes AGAIN.. ++i=++0=1 so it will be one.. Now as OR means. either of the half must not be 0 and so || says, I hv got statement true (Which in case of OR is NOT EQUAL TO 1 by evaluating left portion only) So. OR Says well, I got wat I wan't Don't need to check the other expression and so it won't execute. At that instance the value of the variable are i as I said becomes 1 j and k no execution and x is assigned to 1 as the total expression evaluates as success ( Remember Success means 1 and it not the value of i which is assigned to x ) and so the output will follow as it is. Prem On Sun, Jun 17, 2012 at 12:50 PM, enchantress <elaenjoy...@gmail.com> wrote: > Consider the following code: > > int i=0,j=0,k=0; > int x = ++i || ++j && ++k; > > O/P: x=1,i=1,j=0,k=0 > > Now, the logic operators are evaluated left to right and if the output is > determined by left hand side expression right hand side is not evaluated. > But the precedence of && > || hence ++j&&++k should be dealt with > first.The output says once ++i evaluates to 1 further expression is not > considered. > Can anyone explain this anomaly? > As of i know associativity is considered when precedence of operators is > the same eg: > x*y/z will be evaluated left to right. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/algogeeks/-/rr41g1Q8q38J. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.