RE: [algogeeks] Re: Can anyone explain this strange behavior ?

2012-06-12 Thread Ashot Madatyan
"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  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
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.



Re: [algogeeks] Re: Can anyone explain this strange behavior ?

2012-06-12 Thread nadeem khan
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  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:
>
>> #includeint main(){int i,j,k,m,l;
>> i=-3;
>> j=2;
>> k=0;m=++i || ++j && ++k ;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.
> 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.



Re: [algogeeks] Re: Can anyone explain this strange behavior ?

2012-06-11 Thread Prem Krishna Chettri
Easy Buddy.. this is primary thing.. Surprise to know that ppls still don't
knw abt this..

for OR:-
 if left expr evaluate non zero it won't compute right side.

For And:-
if left expr evalute zero , it won't compute right side

Prem

On Tue, Jun 12, 2012 at 11:10 AM, sengar.mahi  wrote:

> Nope ,the output is correct.as I had studied somewhere ,i don't remember
> where exactly but
> in (x||y) type condition's,if x evaluates to true( non zero) then value of
> y doesn't matter and is not evaluated and condition turns out to be true
> anyhow without even checking y ,control never goes to y and y is never
> executed;
> now in your case m=++i || ++j && ++k;
> since precedence of && is more than or,so we can take it as m=++i || (++j
> && ++k);
> now expression evaluates to true just by checking i++ which is -2 now(non
> zero) and value of ++j && ++k is not even checked nor changed ,hence both j
> and k remain unchanged.
> This is a correct explanation u can rely an this.
> thank you :)
>
>
> On Tue, Jun 12, 2012 at 2:19 AM, Dave  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:
>>
>>> #includeint main(){int i,j,k,m,l;
>>> i=-3;
>>> j=2;
>>> k=0;m=++i || ++j && ++k ;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.
>> 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.



Re: [algogeeks] Re: Can anyone explain this strange behavior ?

2012-06-11 Thread sengar.mahi
Nope ,the output is correct.as I had studied somewhere ,i don't remember
where exactly but
in (x||y) type condition's,if x evaluates to true( non zero) then value of
y doesn't matter and is not evaluated and condition turns out to be true
anyhow without even checking y ,control never goes to y and y is never
executed;
now in your case m=++i || ++j && ++k;
since precedence of && is more than or,so we can take it as m=++i || (++j
&& ++k);
now expression evaluates to true just by checking i++ which is -2 now(non
zero) and value of ++j && ++k is not even checked nor changed ,hence both j
and k remain unchanged.
This is a correct explanation u can rely an this.
thank you :)

On Tue, Jun 12, 2012 at 2:19 AM, Dave  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:
>
>> #includeint main(){int i,j,k,m,l;
>> i=-3;
>> j=2;
>> k=0;m=++i || ++j && ++k ;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.
> 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.



[algogeeks] Re: Can anyone explain this strange behavior ?

2012-06-11 Thread Dave
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:

> #includeint main(){int i,j,k,m,l;
> i=-3;
> j=2;
> k=0;m=++i || ++j && ++k ;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.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.