# NOTs, ORs and ANDs? HELP!!

• 08-28-2001
Unregistered
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.
• 08-28-2001
morbuz
NOT: !=
AND: &&
OR: ||
• 08-28-2001
Stoned_Coder
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.
• 08-29-2001
DavidP
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