1. C + + adds the bool type to the basic type of C language system.
2, the bool type variable in C + + is only true and false,true represents the truth value, the compiler internally with 1, false represents a non-truth, the compiler internally with 0.
3. The C + + compiler converts a non-0 value to True (1) and a value of 0 to False (0) when the value is assigned.
4. Theoretically, the bool variable takes up one byte.
The following program describes the above:
#include <iostream>
using namespace Std;
int main ()
{
bool A = true;
cout<< "bool A" <<a<<endl; Value to verify True
cout<< "sizeof bool" <<sizeof (BOOL) <<endl;//Verify that the BOOL type variable accounts for the memory size
cout<< "sizeof a" <<sizeof (a) <<endl; Verify that the BOOL type variable accounts for memory size
BOOL B = false;
cout<< "bool B" <<b<<endl; Value to verify False
BOOL C = 0;
cout<< "bool C" <<c<<endl; Verify that the value of the BOOL variable value is 0
bool d = 10;
cout<< "BOOL D" <<d<<endl; Verify that the bool variable value is a value other than 0
BOOL E =-10;
cout<< "bool E" <<e<<endl; Verify that the bool variable value is a value other than 0
System ("pause");
return 0;
}
Operation Result:
BOOL a 1
sizeof BOOL 1
sizeof a 1
BOOL B 0
BOOL C 0
BOOL D 1
BOOL E 1
Please press any key to continue ...
Long Press to unlock
Unlock more Insider Stories
Legal programming
: Lightspeed-tech
Technology-driven Life
C + + Note 14: C + + Extensions--new data type bool type