BOOL and bool True vs. false vs. False in C + + (reprinted)

Source: Internet
Author: User
Tags define null

Http://blog.chinaunix.net/uid-28458801-id-3941112.html

The difference between false/true and False/true 1. The difference between false/true and false/true: False/true is a new keyword in the standard C + + language, and False/true is through # define, which is used to solve the difference between the program in C and C + +, the following is false/ True in Windef.h definition: #ifndef false#define FALSE 0#endif#ifndef true#define TRUE 1#endif that false/true is an int type, and false/ True is a bool type; So the two are different, but we don't have this feeling in use, because C + + will do the implicit conversion for you. The 2.bool size differs from BOOL in that bool is 1 bytes in C + + and bool is of type int, and the size of int is dependent on the specific environment; so: false/true only takes 1 bytes, and True/false, depending on the environment, The following is the definition of BOOL in windef.h: the difference between typedef int BOOL;3.NULL and 0: or let's take a look at the definition of NULL in windef.h: #ifndef null#ifdef __cplusplus// This is to indicate that the program is compiled in C + + # # # NULL 0#else#define null ((void *) 0) #endif #endif so there's no difference, but there's a forced type conversion in C. The difference between BOOL and bool one, 1, the type of bool is int type bool is Boolean 2, the length of different bool only one byte bool length depending on the actual environment to be determined, generally can be considered to be 4 bytes 3, the value of different bool value false and True, is the difference between 0 and 1 bool evaluates to FALSE and true, is the difference between 0 and non 0 two: bool is the standard C + + data type, the desired value is true and false. A single byte, if a number of bool objects are listed together, may occupy a bit, depending on the compiler.  bool is a typedef int BOOL defined by Microsoft. Unlike bool, it is a three-valued logic, True/false/error, and an integer with a return value of >0 is true,0 for false,-1 as ERROR. Many functions in the Win32 API that return values of bool are three-valued logic. such as GetMessage (). Three: The difference between a large bool and a small bool: 1, the type of bool is the INT type bool is the Boolean type 2,Length different bool only one byte bool length depending on the actual environment, generally can be considered to be 4 bytes 3, the value of different bool value false and True, is the difference between 0 and 1 bool value false and True, is 0 and non 0 difference 4, example bool x=3;  //alarm bool X=1;  //correct bool x=3;  //correct bool x=3.3;  //Warning NOTE: The underlying variables that Windows defines for compatibility issues. typedef unsigned long        dword;typedef int                   bool;typedef unsigned char         byte;typedef unsigned short      word;typedef float                 float;typedef FLOAT                 *pfloat;typedef BOOL near            *pbool;typedef BOOL Far             *lpbool;typedef BYTE near             *pbyte;typedef BYTE Far            *lpbyte;typedef int near            *pint;typedef int far               *LPINT; 

C + + bool and bool True vs. false vs. false (reprinted)

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.