On Wed, Oct 14, 2009 at 8:23 AM, Asad Abbas <[email protected]> wrote:

> int i,j=2,k=4;
> i=(j>3)&&(++k==6);
> cout << i << k << endl;
> i=(j<3)&&(++k==6);
> cout << i << k;
>
> output:
> 04
> 05

in the statement:

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

the second operand of the && is never evaluated because the first half
evaluates to false (it's a shortcut mechanism in C++, no need to keep
going since we already know the entire statement will evaluate to
false. So k is still 4 until the other line where && is evaluated...
the first half becomes true so the second half is evaluated and k is
increased by one.

-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
    If I were to divulge it, it would overturn the world."
               -- Jelaleddin Rumi

Reply via email to