Like Tree1Likes
  • 1 Post By hk_mp5kpdw

Question about Boolean expression

This is a discussion on Question about Boolean expression within the C++ Programming forums, part of the General Programming Boards category; !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR) The above is from the C++ ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    Question about Boolean expression

    !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)

    The above is from the C++ tutorial. The tutorial gives the answer as 0 (or false) with the explanation, (AND is evaluated before OR).

    My question is: if 1 && 0 is 0 (or false) doesn't the ! outside the parentheses convert the final result to !0 ( 1 or true)?

    Thank you.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,672
    1 || 0 = 1
    !1 = 0
    Don B. likes this.
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    2
    Never mind. I see what I did what.

    B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)

    1 && 0 is evaluated first and results in 0

    then you evaluate:

    1 || 0

    which results in 1 (or True)

    but then the ! negates 1 to !1 or 0 (false).

    Does everyone else have a headache now? :-)

    Quote Originally Posted by hk_mp5kpdw View Post
    1 || 0 = 1
    !1 = 0
    Thanks for your reply.

  4. #4
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Just the matter of precedence and evaluation that a normal person mostly misinterprets...
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. super basic question about boolean evaluation
    By rodrigorules in forum C++ Programming
    Replies: 7
    Last Post: 02-20-2011, 03:48 AM
  2. Expression Tree
    By Coding in forum C++ Programming
    Replies: 5
    Last Post: 07-19-2008, 04:24 PM
  3. Design question.
    By King Mir in forum C++ Programming
    Replies: 5
    Last Post: 05-30-2008, 11:49 AM
  4. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 08:15 AM
  5. Use struct to create a boolean type
    By skyglin in forum C Programming
    Replies: 6
    Last Post: 06-18-2003, 08:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21