Thread: Boolean Question(s);

  1. #1
    Registered User
    Join Date
    Jan 2008

    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
    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
    They are not the same, in fact, I wrote an example program to demonstrate this just today:

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

  5. #5
    Registered User
    Join Date
    Jan 2008
    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
    Replies: 23
    Last Post: 12-26-2004, 09: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