Let's concentrate on if condition,

*if (++k < 5 && k++/5 || ++k <= 8);*

is equivalent to (based on operator precedence)

*if (((++k < 5) && (k++/5)) || (++k <= 8));*

Initially k = 5.

Step1 : The first term in if clause i.e, (++k < 5) is false which makes the
*((++k < 5) && (k++/5)) *false because all the variables in && should be 1.

this makes k = 6 because of execution of (++k < 5).

Step 2 : Now if condition is equivalent to if(0 || (++k <= 8))

it will check the second condition, (++k <= 8) thereby incrementing k by 1
and returns 1 (making if condition true though it's not relevant for this
problem)

Hence, k = 7 after execution of this program.



On Tuesday, November 6, 2012, Anil Sharma wrote:

> main()
>      {
>       int k = 5;
>       if (++k < 5 && k++/5 || ++k <= 8);
>       printf("%d ", k);
>      }
>
> the output shud be 8 but it comes out to be 7.why???
> as increment operator has higher precedence among them so increment shud
> be done throughout at first and after then other operators shud be
> evaluated.so    output shud be 8.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>


-- 

Aamir Khan | 4th Year  | Computer Science & Engineering | IIT Roorkee

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to