"k should be 1 right???? "
No, it shouldn't be because the expression evaluation will stop at the very
first sub-expression as soon as it evaluates to true in the "m=++i || ++j &&
++k ; "
And the first sub-expression that evaluates to true is the " ++i "
 
Rgds,
Ashot

 

From: algogeeks@googlegroups.com [mailto:algogeeks@googlegroups.com] On
Behalf Of nadeem khan
Sent: Tuesday, June 12, 2012 6:39 AM
To: algogeeks@googlegroups.com
Subject: Re: [algogeeks] Re: Can anyone explain this strange behavior ?

 

i=-3  it gets incremented to -2 (++i)

m is evaluated and as ++i is non zero it evaluates to TRUE and m is assigned
value 1,  hence remaining part is not executed , so j and k is not
incremented.

 

On Tue, Jun 12, 2012 at 2:19 AM, Dave <dave_and_da...@juno.com> wrote:

This is the result of short-circuit evaluation. See, e.g.,
http://en.wikipedia.org/wiki/Short-circuit_evaluation, or this topic in your
language reference.

 

Dave


On Monday, June 11, 2012 2:28:52 PM UTC-5, ((** VICKY **)) wrote:

#include<stdio.h>
int main()
{
int i,j,k,m,l;
i=-3;
j=2;
k=0;
m=++i || ++j && ++k ;
 <http://www.opengroup.org/onlinepubs/009695399/functions/printf.html>
printf("\n%d %d %d %d",i,j,k,m);
return 0;
}
 
o/p: -2 2 0 1
 
 
 
k should be 1 right???? 

 

-- 
Cheers,

 

  Vicky

 

-- 
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/-/8PoAya7NqjYJ.


To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to
algogeeks+unsubscr...@googlegroups.com
<mailto:algogeeks%2bunsubscr...@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.

-- 
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.

Reply via email to