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 he 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 needs an arithmetic value, the Boolean type object will be implicitly converted to the int type, which is the shape of the object, False is 0,true is 1, please 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 ();
}
A+found such expression is set up, the output value of 2 for the addition operation!
So there's a lot of people here who would ask, "Can you?" 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.