Thread: AND OR NOT logical && || !

  1. #1
    Registered User sballew's Avatar
    Join Date
    Sep 2001

    Question AND OR NOT logical && || !

    I am still needing help understanding logical operators.

    assuming i = 4 and j = 2 and k = -2
    what do the following yield???

    printf("%d ",  !i < j );
    printf("%d", !!i < !j );
    printf("%d ", i && j || k );
    printf("%d", i < j || k );
    what does !i mean?
    what does !!i mean?
    what does !i < j mean?
    what does !!i < !j mean?
    what does i && j mean?
    what does i && j || k mean?

    I am confused. When I input the above code in and compiled and ran, I got a result of [size=huge]1[/size] for each print function called.

    Sue B.

    dazed and confused

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    what does !i mean?

    well if i is true (anything other than 0) then !i (not i) is false(0) and vice-versa.

    what does !!i mean?

    not not i so if i is true not not i is true.

    what does !i < j mean?

    if i is true then !i becomes false and is it less than j? will be a true or false answer.

    what does !!i < !j mean?

    i think you can do this one now.

    what does i && j mean?

    are i and j both true. If so true else false.

    what does i && j || k mean?

    the result of i && j is then ored with k.or will produce true if one or both of its operands are true.

    there is a thread on the c++ board about bitwise operators. Read that everything that applies to bits applies to boolean logic just on a slightly different scale.(with logical operators we are not testing/setting individual bits).
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :-

  3. #3
    Registered User minime6696's Avatar
    Join Date
    Aug 2001

    Lightbulb Im simpler terms...

    Basically, read it in english outloud, and you will understand...

    Like this:

    !i > j

    not i is greater than j
    (!i) > j

    Well !i will only return a true or a false : false if i is true, and true is i is false.

    (!i) is greater than j
    The revearse boolean of i is greater than j.

    Assuming i is nonzero and j is 6:

    1 > 6
    This will return false.


    P.S. Few im finding myself ending my sentances with ';' instead of '.';

Popular pages Recent additions subscribe to a feed