boolean help

This is a discussion on boolean help within the C++ Programming forums, part of the General Programming Boards category; hey...first time posting....i'm trying to get my programming skills back after 8 years of not using them. uphill battle, to ...

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    2

    boolean help

    hey...first time posting....i'm trying to get my programming skills back after 8 years of not using them. uphill battle, to say the least.

    in any event, in going through the tutorials i hit a snag with the boolean operators AND, NOT, and OR.

    i understand that they are processed in a specific (not, and, or) order, but within a complex statement how does it get processed?

    the quiz example is !(1 && !(0 || 1))....what is the order of operations for this statement?

    thanks for the help understanding this.
    Last edited by seekerofthetao; 05-09-2010 at 10:09 PM. Reason: stupidity

  2. #2
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    You figure it out the same way you do for arithmetic operators if you remember PEMA- Parenthesis, exponents, multiplication, addition. The boolean negation, AND and OR operators are analogous to the arithmetic negation, multiplication and addition operators.
    Parenthesis are evaluated first, followed by negation, and and or.
    So the expression you posted is analogous to
    -(1 * -(0+1))
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    2
    thank you very much. i had a feeling that it was easier than i was making it out to be.

  4. #4
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    But of course the compiler will only evaluate the parantheses if the first expression turns out to be true. It goes left-to-right and stops as soon as the result is known (for example if it encounters '0 && 1' it evaluates 0, which turns out to be false, and stops cuz the expression has to be false, too)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why only boolean? Why not quadlean?
    By Dino in forum Tech Board
    Replies: 15
    Last Post: 11-21-2009, 03:04 PM
  2. Novice needs help
    By ghaasemi in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2009, 08:20 AM
  3. Casting boolean as string
    By doofusboy in forum C Programming
    Replies: 11
    Last Post: 11-10-2005, 11:24 AM
  4. Working with boolean...
    By CompiledMonkey in forum C Programming
    Replies: 4
    Last Post: 11-03-2003, 09:39 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