NOTs, ORs and ANDs? HELP!!

This is a discussion on NOTs, ORs and ANDs? HELP!! within the C++ Programming forums, part of the General Programming Boards category; I am just starting to learn C++ and I can't figure out NOTs, ORs, and ANDs. they are very confusing ...

  1. #1
    Unregistered
    Guest

    Unhappy NOTs, ORs and ANDs? HELP!!

    I am just starting to learn C++ and I can't figure out NOTs, ORs, and ANDs. they are very confusing and i can't figure them out. The tutorial helps but I just can't figure them out. If any one can help explane it to me that would help alot.

  2. #2
    Registered User morbuz's Avatar
    Join Date
    Aug 2001
    Posts
    35
    NOT: !=
    AND: &&
    OR: ||
    [Signature here. (Remove this!)]

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    ok lets look at them one at a time...

    first not !

    this reverses a boolean value. A boolean value can either be true or false.In computer terms thats 1 or 0.

    so imagine
    x=10
    if (x) { blah blah} blah blah will be executed because if (x) means if(x != 0) != is the not equal to operator.

    now to reverse this we can say

    if (!x) {blah blah} now blah blah will be executed only if x was equal to zero.This is good shorthand coding and very readable when you get used to it.

    logical or ||

    This is used when you want two things checked and want one or both of them to be true ....

    x=10
    y=20

    if (x==10 || y==5) {blah blah} blah blah will be executed because one of the conditions has been met.

    logical and &&

    this is used like logical or except that it only produces a true result when both conditions are met. if for instance you replace the || with && in above then blah blah will not be executed but if this was the condition :-

    if (x==10 && y==20) {blah blah} now blah blah will be executed because both conditions are true.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    Just think of AND's as multiplication, OR's as addition, and NOT's as changing the value to its opposite (a 1 to a 0, and a 0 to a 1).

    1 * 1 + 0 = 1
    1 AND 1 OR 0 = 1

    1 * 0 + 0 = 0
    1 AND 0 + 0 = 0

    NOT(1) AND 0 OR 1 = 1
    0 * 0 + 1 = 1
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

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