Boolean objects can be granted true or false text values. The corresponding relationship is the concept of true or false!
We usually use it to determine whether a condition is true or false, for example, the following code:
// Program Author: Guan Ning
// Site: www.cndev-lab.com
// All the manuscripts are copyrighted. If you want to reprint them, be sure to use the famous source and author.
# Include <iostream>
Using namespace std;
Void main (void)
{
But some people with unclear concepts do not know that Boolean objects can also be considered as integer objects, but they cannot be declared as signed, unsigned, short long, if your life is (short bool found = false;), it will cause compilation errors.
The concept of Integer type is as follows:
When an expression requires an arithmetic value, a Boolean object is implicitly converted to an int type, that is, an integer object. false indicates 0, and true indicates 1. See the following code!
#include <iostream>
#include <string>
using namespace std;
void main(void)
{
bool found = true;
int a = 1;
cout << a + found << endl;
cin.get();
}
The expression style like a + found is true, and the output value is 2!
So many people will ask if the pointer is okay? The answer is yes. This concept is also effective for pointers. Let's look at an example of using an integer pointer object as a Boolean object:
# Include <iostream>
Using namespace std;
Void main (void)
{
Int a = 1;
Int * pi;
Pi = &;
If (* pi)
{
Cout <"* pi is true" <endl;
}
Cin. get ();
}
In the above Code, * pi is converted to a boolean type of implicit pattern to true or true.