# Thread: Newbie with C++ NOT, OR, AND operators question...

1. ## Newbie with C++ NOT, OR, AND operators question...

Hello,

This is my first post on Cprogramming.com as i have just got started with learning C++ from the tutorial area on this website which at the moment is going quite good. However i'm onto the part what explains about the NOT, AND, OR operators. I'm at the last section of the IF statements page currently where it gives an example of the following below:

A. !( 1 || 0 ) ANSWER: 0
B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)
Does the first example (A) does the OR operator take place first? So the 1 || 0 would be TRUE and then the NOT operator comes in and changes it to False which gives it a value of 0?

Is that how it works?

many thanks, Josh.

2. Yes, because the parenthese establish the order here.

3. Ok thanks, i now know how to first to examples work but i don't quite understand how the last example works:

C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)
What would come first in that? the && operator has the value of 0, does that mean it's false? and then the OR operator is true but doesnt the NOT operator make it false after the OR operator has made it True, i'm confused to how it would get the ANSWER: 1 because wouldnt the NOT operator set it back to false?

thanks, Josh.

4. All paranthesises goes first. Just like math.

First (1 || 0) is evaluated.
Then the answer of that && 0 is evaluated.
So:

(1 || 0) --> 1
1 && 0 --> 0
!0 --> 1

Easy.

5. Hello,

Thanks! I see how it work's now, just didn't click too well when i first saw it.

Thankyou, Josh.