simple C question...

Discussion in 'OT Technology' started by Oddo, Mar 24, 2007.

  1. Oddo

    Oddo And then Trogdor smote to Kerrek and all was laid

    Joined:
    Oct 21, 2002
    Messages:
    571
    Likes Received:
    0
    Location:
    houston
    If i=4, j=9, m=-8, p=0 and q=1



    is this true or false? And why, this queston really confused me.

    !p && !(m+p)


    Could anyone tell me why this is a false statement?


     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    anything that is not zero is true. zero is false.

    ! = not
    && = and

    So:

    !p = !0 = !false = true

    !(m+p) = !(-8+0) = !(-8) = !(true) = false

    true && false = false


    answer is "false"
     
  3. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Yes, as jolly said, anything that's not 0 is "true" in C. Perhaps it should be noted that this stems from the fact that C doesn't have a boolean type like some other languages, so there is really no notion of true and false except in conditions, where 0 is "false" and non-zero is "true."
     

Share This Page