Thread: boolean help

  1. #1
    Registered User
    Join Date
    May 2010

    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
    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
    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
    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, 04: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, 12:24 PM
  4. Working with boolean...
    By CompiledMonkey in forum C Programming
    Replies: 4
    Last Post: 11-03-2003, 10: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