EmbLogic's Blog

Project 01

I thought i am done with operators and expressions in C…But i was wrong.

Expressions ++x && ++y || ++z , is evaluated with my logic. But the logic failed when i tried  ++x || ++y && ++z. :(

3 Responses to Project 01

  1. Deepak garg says:

    I face same problem as u faced if U get the concept plz explain on the post.

  2. rahul1989 says:

    ++x && ++y || ++z
    The above expression is evaluated on the basis of precedence order.

    ++(variable) > && (logical and) > || (logical or ) precedence order

    It means that the expression is evaluated as ((++x && ++y ) || ++z))

    let assign x =1, y = 2, z = 3
    the expression is evaluated as

    x = 2, y = 3, z = 3

    Note that is NOT evaluated because
    CASE 1
    (value1) && (value2)
    when value1 = 0, The result become 0 either another value2 = 0 or value2 = 1,
    so compiler will NOT evaluate other value2 if left side value1 is 0,
    the right side value is evaluated only if left side value1 is equal to 1.

    CASE 2
    (value1) || (value2)
    when value1 = 1, The result become 0 either another value2 = 1 or value2 = 0,
    so compiler will NOT evaluate other value2 if left side value1 is 1,
    the right side value is evaluated only if left side value1 is equal to 0.

    I hope you got understand.

  3. I understood your logic Sir, i too had same…But the result of expression ++x || ++y && ++z; (with x =-1).is not as this logic.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>