Boolean statments

This is a discussion on Boolean statments within the C++ Programming forums, part of the General Programming Boards category; I've been reading the tutorials and was clipping along really well but then i got the the boolean statements. How ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    3

    Boolean statments

    I've been reading the tutorials and was clipping along really well but then i got the the boolean statements. How to break them down is confusing me and I'm not sure if its because I have myself stuck on working problems like im in a math class or what so if theres someone that might explain them differently or in more detail then the tutorial does that would be great

    A. !( 1 || 0 ) ANSWER: 0
    B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
    C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

    these are what they give for problems and I think whats keeping me stuck is im not sure where to start. It says to start with the NOT and i know which is which just not sure how to evaluate

    NOT !
    AND &&
    OR ||

    If someone could take the time to give me a bit more explanation i would be greatfull

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,620
    1 is true and 0 is false:

    || returns true if either or both operands are true, and false otherwise

    && returns true if both operands are true, and false otherwise

    ! returns false if passed a true and vice-versa

    && is evaluated before ||, that's why parenthesis are useful
    ( just as * is evaluated before + )
    Devoted my life to programming...

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,620
    I forgot, ! is evaluated before all
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    3
    Ok so the ! are suppose to be first but is that only if theres nothing in parenthasis? If not can you show me in like a function tree of how these are done

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    3
    Ok thanks for the help everyone i was tripped up with it telling me that i needed to evaluate the ! first when i needed to just go with the formal order of operations and do the things in parenthasis first and after realizing this i have got the correct answer on all three questions they have on the tutorial as well as the one on the quiz, Again thanks for the help

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    3
    Learning is a slow and steady process. Take your time in order to grasp concepts. Don't rush.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice needs help
    By ghaasemi in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2009, 08:20 AM
  2. Casting boolean as string
    By doofusboy in forum C Programming
    Replies: 11
    Last Post: 11-10-2005, 11:24 AM
  3. Replies: 4
    Last Post: 04-02-2004, 06:30 PM
  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