Boolean characters

This is a discussion on Boolean characters within the C++ Programming forums, part of the General Programming Boards category; hi I'm andrew.
I'm new here, I've been reading the tutorials but I haven't gone past the second because the ...

Boolean characters

hi I'm andrew.
I'm new here, I've been reading the tutorials but I haven't gone past the second because the answers to the questions arent obvious to me. I was wondering if somebody could explain to me the reason for the answers please.

I'll start with the first one. Always start from the inside of parentheses. The || operator returns true (which is 1 in this case) if either side of the expression is true. So 1 || 0 evaluates to 1 because true OR false evaluates to true. That leaves !(1). The parentheses are not necessary there since there is a single value inside, so that leaves !1. The ! operator evaluates to the opposite of the expression. So !true is false and !false is true. In this case, that means that !1 is 0.

Now how would you get the answer to the other two based on that and what you learned from the tutorial?

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

>> 0 || 0 =1
Remember, operator || evaluates to 1 only if one side or the other side is 1. Also, where did the 0 || 0 come from in the problem? There is a big and important difference between || and &&.

NOT: The NOT operator accepts one input. If that input is TRUE, it returns FALSE, and if that input is FALSE, it returns TRUE. For example, NOT (1) evalutes to 0, and NOT (0) evalutes to 1. NOT (any number but zero) evaluates to 0. In C NOT is written as !. NOT is evaluated prior to both AND and OR.

AND: This is another important command. AND returns TRUE if both inputs are TRUE (if 'this' AND 'that' are true). (1) AND (0) would evaluate to zero because one of the inputs is false (both must be TRUE for it to evaluate to TRUE). (1) AND (1) evaluates to 1. (any number but 0) AND (0) evaluates to 0. The AND operator is written && in C. Do not be confused by thinking it checks equality between numbers: it does not. Keep in mind that the AND operator is evaluated before the OR operator.

OR: Very useful is the OR statement! If either (or both) of the two values it checks are TRUE then it returns TRUE. For example, (1) OR (0) evaluates to 1. (0) OR (0) evaluates to 0. The OR is written as || in C. Those are the pipe characters. On your keyboard, they may look like a stretched colon. On my computer the pipe shares its key with \. Keep in mind that OR will be evaluated after AND.

That explains it pretty well. If you don't get it, try looking at some truth tables:

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell

>> 1 || 0 = 1 =0one or zero equals one and with the not (!) I musta change the answer to the oposite, that being 0
Ok, explain in words what you are thinking here.

>> 0 || 0 =1 correction 0 && 0 = 0 =1 because of !(first zero representing the first equation and the second representing the original && 0 and then the answer being changed by !)
Remember, operator || evaluates to 1 only if one side or the other side is 1. Also, where did the 0 || 0 come from in the problem? There is a big and important difference between || and &&.

"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell