
Originally Posted by
lalakijilp
non of the above examples uses a boolean...

they are all examples of if and while statements
a boolean is a datatype that can only have the value true or false
true ==1
false ==0
example copied from a site:
Code:
#include <iostream>
using namespace std;
int main() {
bool b;
b = false;
cout << "b is " << b << endl;
b = true;
cout << "b is " << b << endl;
if(b) // control the if statement
cout << "This is executed.\n";
b = false;
if(b)
cout << "This is not executed.\n";
// outcome of a relational operator is a true/false value
cout << "10 > 9 is " << (10 > 9) << endl;
return 0;
}
example A.
you start with the or.
1 or 0 = 1 inverted 0
example B.
1 or 1&&0
1= 1

1&&0 = 0
so
1 or 1&&0
is 1 0r 0 = 1 inverted =0
example C.
( 1 || 0 ) && 0
always first between the brackets so...
1 or 0 = 1
1&& 0 = 0 inverted is 1
You're not wrong, boolean does return true or false, true being 1, false being anything but 1. AJ is asking about the boolean OPERATORS I believe. The operators being !, && and ||. != Not, && = And, || = Or.
Now you go through an analyze how each works.
I'll start with the operator which is evaluated first.
&& is the first boolean operator to be evaluated if there is more than one operator present. It compares two values, if either value is false, then the whole && comparison is false, i.e. 1 && 0 would return false because one of the values is false. 1&&1 would return true because both values are true.
|| is evaluated second after &&, || compares 2 values just like &&. If either value compared is true, then the whole || comparison is true, i.e. 1 || 0 evaluates to true because one of the statements is true. 0 || 0 returns false, because neither value is true.
! is to be evaluated lastly and is most likely outside of the parenthesis containing the other boolean operators. Whatever the value is found within the other comparisons, would be reversed. IE. !(1||0), 1||0 will return true, because one of the values is true. But the ! operator outside of the statement reverses that making the statement false. So !(1||0) will return false.
Parenthesis are useful aswell, because the operators must be evaluated in a certain order, you can modify that order through parenthesis. IE
!(1||0) &&0). Normally you would evaluate the && operator first, but because 1||0 are inside parenthesis before that, you will evalue that first. So 1||0 evaluates to True, because one of the values is true. Then you evaluate that value with the && operator so the problem would look like this at this point.
!(1&&0). Now we will evaluat 1&&0 since you evaluate && before !. 1&&0 evaluates to false, because one of the values is false. So we would now have this.
!(0) And now lastly we evaluate the ! operator. So of course, if the answer is NOT 0, then it is of course 1, or true.
=D Hope I helped ya.
BTW fags, don't call me a C+P'er, google it. =) Hand typed.