Question

This is a discussion on Question within the C Programming forums, part of the General Programming Boards category; Q1.Which 1 will return a false value? a) true && true || false b) false || true c) (false || ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    77

    Question

    Q1.Which 1 will return a false value?

    a) true && true || false
    b) false || true
    c) (false || true) && true
    d) (false || true) || true


    Q2.what is a post test loop?

    a)do...while
    b)while
    c)both the for and the while
    d} both the while and the do....while

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    OK, I've got my answers, now lets see yours.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by cpjust View Post
    OK, I've got my answers, now lets see yours.
    i dont have the correct answer.. i choose Q1 B Q2a.. plz explain Q1 for me thx

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Either you haven't written down the Q1 correctly, or the question itself is a trick question where NONE of the answers is right.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by matsp View Post
    Either you haven't written down the Q1 correctly, or the question itself is a trick question where NONE of the answers is right.

    --
    Mats
    can u show me an example of return a false value?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    false, !true, false && true, true && false, false || false, etc.

    Sorry, but there are ENDLESS combinations of boolean logic that end with false.

    The problem in the question posted is that either side of an || statement always have a true result, which means the end result will ALWAYS be true.

    Code:
    true && true || false
    false || true
    (false || true) && true
    (false || true) || true
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by matsp View Post
    false, !true, false && true, true && false, false || false, etc.

    Sorry, but there are ENDLESS combinations of boolean logic that end with false.

    The problem in the question posted is that either side of an || statement always have a true result, which means the end result will ALWAYS be true.

    Code:
    true && true || false
    false || true
    (false || true) && true
    (false || true) || true
    --
    Mats
    if this? (false || true) && false

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    yes, that will return false.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    489
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  10. #10
    Registered User
    Join Date
    Mar 2009
    Posts
    77
    Quote Originally Posted by matsp View Post
    yes, that will return false.

    --
    Mats
    can u help me with swapping?printing backward thx
    Last edited by archriku; 05-07-2009 at 07:41 AM.

  11. #11
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by archriku View Post
    Q1.Which 1 will return a false value?

    a) true && true || false
    b) false || true
    c) (false || true) && true
    d) (false || true) || true

    Q2.what is a post test loop?

    a)do...while
    b)while
    c)both the for and the while
    d} both the while and the do....while
    1.None. These are logical operators and return either true(1) or false(0) as their result. If both the operands of && are true then only && will return true, in all other case it will return false. For || if any one of the operators is true then the result will be true. For && if the first expression evaluates to false the second is not evaluated. For || if the first expression evaluates to true the second is not evaluated. The precedence of && is higher than ||.
    2. do while is the only post test loop. This means that the body of the loop will be executed at least once.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21