Bool and bool are different (bool is not a C keyword, and bool in C ++ is not an int)

Source: Internet
Author: User
    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 solved through # define.ProgramIn the differences between C and C ++ environments, the following is the definition of false/true in windef. h:
# 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.

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

Related Article

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.