A Boolean type object can be given literal value true or false, and the corresponding relationship is the concept of true and false.
The method we usually use is to use him to judge the true and false conditions, such as the following code:
#include <iostream>
using namespace Std;
void Main (void)
{
BOOL found = true;
if (found)
{
cout << "found condition is true!" << Endl;
}
}
But some people who are not clear about the concept of a Boolean type can also be considered an object of an integer type, but it cannot be declared as Signed,unsigned,short long, if you generate (short bool found=false;), This will result in a compilation error.
This is the concept of an integer type:
When an expression requires an arithmetic value, the Boolean type object will be implicitly converted to the int type, which is the Shape object, and False is 0,true is 1, see the code below.
#include <iostream>
#include <string>
using namespace Std;
void Main (void)
{
BOOL found = true;
int a = 1;
cout << A + found << Endl;
Cin.get ();
}
A+found Such an expression is established, the output value of 2 for the addition operation.
So when it comes to this, a lot of people ask the pointers. The answer is yes. Such a concept is also valid for pointers, and let's take a look at an example of using an shaping pointer object as a Boolean object:
#include <iostream>
using namespace Std;
void Main (void)
{
int a = 1;
int *pi;
pi=&a;
if (*PI)
{
cout << "*pi is true" << Endl;
}
Cin.get ();
}
The *PI in the code above makes a Boolean-type conversion of the implicit pattern to mean true.