Boolean Question(s);

This is a discussion on Boolean Question(s); within the C++ Programming forums, part of the General Programming Boards category; My very first question has to do with the tutorial quiz for If statements. 1. Which of the following is ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    28

    Boolean Question(s);

    My very first question has to do with the tutorial quiz for If statements.

    1. Which of the following is true?
    A. 1
    B. 66
    C. .1
    D. -1
    E. All of the above

    I picked 1. It doesn't exactly specify in the tutorial what happens to a number other than 0 and 1. I could have sworn that numbers other than 1 led to false by default. I'm probably wrong like usual about programming but I would just like a definite answer.

    2. Which of the following is the boolean operator for logical-and?
    A. &
    B. &&
    C. |
    D. |&

    I would like to know what the difference between logical-and and and is. I guessed B which is correct which leads me to assume they are the same thing. Am I correct? Again, it doesn't specify in the tutorial so I'm led to ask this probably simple question.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    1) It's a little ambiguous. If a number is used in an if or while statement, then nonzero is true and zero is false. On the other hand, if boolean true or false is converted to a number, then true becomes 1 and false becomes 0. So complain to whoever wrote the quiz. I'm guessing the correct answer is supposed to be E but it's not totally clear.

    2) Logical and is &&. Bitwise and is &. Google for "logical and" and "bitwise and".

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    They are not the same, in fact, I wrote an example program to demonstrate this just today:

    logic optimization

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    E & B.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    28
    Thanx! This helped a lot.

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. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 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