C++ Basic Learning 1: C++ Boolean Type

Boolean type ( bool ) is a new basic data type in C++ . The bool type is not defined in the standard C language. If you need to use the bool type,
Programmers can customize a bool type through macro definitions. The definition statement is as follows:

#define bool int
#define false 0
#define true 1

That is, the int type is defined as a bool type, and the two values ​​​​of the int type are defined as the two values ​​of the bool type, true and false, respectively.

But in C ++, there is no need for such trouble, the bool type has been defined in C++.

The bool type is one of the basic data structures of the C++ language. On the 80x86 processor, the compiler gcc 4.8.1 and Visual C++ 2012 allocate 1 byte length to the bool type variable.

The bool type has only two values: true and false. When doing logical operations, the default non-zero value is true.

Defining a bool type variable is also similar to the definition of other primitive data type variables, as follows:


bool flag = true;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324601205&siteId=291194637