@shady : lazy evaluation .... if first condition in OR is true... second condition wont be evaluated
On Wed, Jul 13, 2011 at 10:21 PM, shady <sinv...@gmail.com> wrote: > && has higher precedence than || > > but why does j and k didn't increase after the statement > l= ++i || j++ && k++; > got executed ? > > On Wed, Jul 13, 2011 at 10:07 PM, sagar pareek <sagarpar...@gmail.com>wrote: > >> For more clarification....try this :- >> >> int i=1,j=1,k=1,l; >> l= ++i || j++ && k++; >> printf("%d %d %d %d",i,j,k,l); >> >> o/p will be 2 1 1 1 >> because as vaibhav wrote the equation evaluate as l= ++i || (j++ && k++); >> only ++i evaluate not other two increments :) >> >> On Sun, Jul 10, 2011 at 11:31 PM, rShetty <rajeevr...@gmail.com> wrote: >> >>> Got it Thanks ..... >>> >>> On Jul 10, 10:40 pm, vaibhav shukla <vaibhav200...@gmail.com> wrote: >>> > associativity comes into play when operators are of same precedence. >>> > >>> > On Sun, Jul 10, 2011 at 11:08 PM, vaibhav shukla < >>> vaibhav200...@gmail.com>wrote: >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > > && has higher precedence than || >>> > > the expression is evaluated as >>> > > z=j || ( k && i ); >>> > > hence the output i.e 1 ;) >>> > >>> > > On Sun, Jul 10, 2011 at 11:06 PM, rShetty <rajeevr...@gmail.com> >>> wrote: >>> > >>> > >> #include<stdio.h> >>> > >> int main() >>> > >> { >>> > >> int i=0,j=1,k=1,z=0; >>> > >> z = j || k && i ; >>> > >> printf("%d",z); >>> > >> return 0; >>> > >> } >>> > >>> > >> The output is 1 for the above program . >>> > >>> > >> But according to associativity of logical operators , the evaluation >>> > >> should be from left to right , But is it taking from right to left ? >>> > >> What is the exact concept for the program behavior above? >>> > >>> > >> -- >>> > >> 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. >>> > >>> > > -- >>> > > best wishes!! >>> > > Vaibhav Shukla >>> > > DU-MCA >>> > >>> > -- >>> > best wishes!! >>> > Vaibhav Shukla >>> > DU-MCA >>> >>> -- >>> 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. >>> >>> >> >> >> -- >> **Regards >> SAGAR PAREEK >> COMPUTER SCIENCE AND ENGINEERING >> NIT ALLAHABAD >> >> -- >> 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. >> > > -- > 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. > -- best wishes!! Vaibhav Shukla DU-MCA -- 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.