Thread: quick question

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    16

    quick question

    reviewing for my final and my professor posted some example questions that might be on the test i know you guys on here dont help with homework but this isnt homework just a question of what you guys think is the right answer since he does not post the answers... the question:

    Which of the following is logically equivalent to the Boolean expression

    (val != 0 || val != 1) ?

    a) val >= 0 b) val <= 2 c) 0 d) 1 e) none of the above


    personally i think its none of the above by i just want to make sure im studying the right concepts well thanks for the help

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I vote d.

    Find a value for val that will NOT produce 1.

    Alternatively, find a way for both expressions to ever be false. If val is 0, it isn't 1. If it's 1, it isn't 0. There is no way you can make it both not equal to 1 and not equal to 0.... which is the only way you can get 0. Both sides must be 0 for the entire expression to be 0.

  3. #3
    Daring to be a guru
    Join Date
    Dec 2007
    Posts
    14
    i will probably say that all values for val right from -65k to +65k for int val or for long type or any number datatype would go true. so i would say the correct option is not there.

    But for me if there is an option all the above or like that then it will go.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    The question is about the logical value of the boolean expression, not what values val can take.

  5. #5
    Daring to be a guru
    Join Date
    Dec 2007
    Posts
    14
    sorry i propably misunderstood the question then it is always 1 ie option d

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    (val != 0 || val != 1)
    Is equivalent to:
    Code:
    !(val == 0 && val == 1)
    Since val cannot be both 0 and 1, that is equivalent to !(0) which is 1 (option d).
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM