In C++, a Boolean is a data type that represents logical values. It can hold one of two possible values:
- true (typically representing a condition that is correct or valid).
- false (typically representing a condition that is incorrect or invalid).
The bool type in C++ is used to store these values, and it’s commonly used in decision-making structures like if statements or loops, where the program needs to evaluate conditions as either true.
Example: Use Boolean value false
#include <iostream>
using namespace std;
int main() {
bool isManager = true;
if (isManager) {
cout << "John is Manager." << endl;
} else {
cout << "John is Developer." << endl;
}
return 0;
}
Output:
John is Manager.
Example: Use Boolean value false
#include <iostream>
using namespace std;
int main() {
bool isEmployeeActive = false;
if (isEmployeeActive) {
cout << "Employee is active." << endl;
} else {
cout << "Employee is not active." << endl;
}
return 0;
}
Output:
Employee is not active.