C++/Data Type/Bool
Define and use bool value
<source lang="cpp">
- include <iostream>
using namespace std; int main() {
bool outcome; outcome = false; if(outcome) cout << "true"; else cout << "false"; return 0;
}
</source>
Demonstrate bool values.
<source lang="cpp">
- 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;
}
</source>