C++ learning 1-bool data type

Boolean type (bool) is a new basic data type in C++. The bool type is not defined in the standard C language. If the bool type needs to be used, the
programmer can customize a bool type through macro definition. The definition statement is as follows:

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

is to use int The type is defined as bool type, and the two values ​​​​of int type 0 and 1 are defined as two values ​​of 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 variables of type bool is also similar to the definition of variables of other primitive data types, as follows:


bool flag = true;

Guess you like

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