In C language, we talk about the concept of logical value , that is, by judging the value 1 as true and 0 as false, but there is no special type support. In C++, there is clear type support, that is, the bool type , which can only represent false (false) or true (true). This type only occupies one byte in size. You can try to define variables of this type and assign values. and output like:
#include<iostream>usingnamespacestd;intmain(){boola=true;boolb=false;cout<<a<<endl<<b<<endl;return0;}
You can test it on your own, and you will get the output. You can see that the output results are still 1 and 0, not true and false. You should pay attention to this. The emergence of the bool type gives C++ a special variable type that represents true and false types, which facilitates us to have special types to represent status, switches and other logical methods during the programming process. This is an improvement of C++ compared to C.
Please understand and digest!