On Wed, Oct 14, 2009 at 1:23 PM, Asad Abbas <[email protected]> wrote:
> CODE:
>
> int i,j=2,k=4;
> i=(j>3)&&(++k==6);

The && shortcuts at the first expression since j is less than 3. i
becomes the result of (j>3) which is 0, k doesn't get incremented so

> cout << i << k << endl;
i == 0, k == 4.

> i=(j<3)&&(++k==6);

(j<3) is true, however (++k ==6)  is false because it's ==5 (because
of the above) resulting in the whole expression (&& isn't shortcut
here) being false (i.e. 0).

> cout << i << k;
>
> output:
> 04
> 05
>
> //why it is not printed as
> 05
> 16



-- 
PJH

http://shabbleland.myminicity.com/
http://www.chavgangs.com/register.php?referer=9375
http://www.kongregate.com/?referrer=Shabble

Reply via email to