Bool and bool

Source: Internet
Author: User
Bool and bool

1. bool Definition

Typedef int bool;

# Define false 0

# Define true 1

It cannot be fully overloaded (bool is essentially INT), for example:

// File. h void F (INT); // OK

Void F (bool); // OK //

File. cpp

Void F (INT ){/*.... * //} // OK

Void F (bool ){/*.... */}//
Error, re-declare

2. bool (false, true) is a built-in C ++ type, which can avoid the above problems.

 

Bool occupies 1 byte in C ++, while bool is of the int type. The size of the int type depends on the specific environment. So: false/true only occupies 1 byte, while
True/false depends on the specific environment.

 

 

The following is the definition of bool in windef. h:

Typedef int bool;

False/true is the new keyword in the Standard C ++ language, while false/true is the result of # define, which is used to solve the environment difference between the program in C and C ++, the following values are false/true in windef. h definition:

# Ifndef false

# Define false 0

# Endif

# Ifndef true

# Define true 1

# Endif

That is to say, false/true is the int type, while false/true is the bool type. So they are different, but we do not feel this way in use, because C ++ will help you perform implicit conversion.

 

C ++ in Linux
The compiler must use g ++. Otherwise, the compiler does not know the bool type.

 

In short, the differences between big bool and small bool:

 

1. Different Types

 

Bool is int type

 

Bool is Boolean

 

2. Different Lengths

 

Bool has only one byte

 

The bool length depends on the actual environment. Generally, it can be regarded as 4 bytes.

 

3. Different values

 

Bool values: false and true, which are the difference between 0 and 1.

 

Bool values: false and true, which are the difference between 0 and non-0.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.