Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between BOOL and bool?

In VC++ we have the data type “BOOL” which can assume the value TRUE or FALSE, and we have the data type “bool”, which can assume the value true or false.

What is the difference between them and when should each data type be used?

like image 269
Umesha MS Avatar asked Jun 21 '11 04:06

Umesha MS


People also ask

What is difference between bool and bool in C#?

bool can contain only true and false values while bool? can also have a null value. Show activity on this post. bool means you can have values of true and false.

Is bool and Boolean are same?

In computer science, the Boolean (sometimes shortened to Bool) is a data type that has one of two possible values (usually denoted true and false) which is intended to represent the two truth values of logic and Boolean algebra.

Is bool always 0 or 1?

Boolean values and operations C++ is different from Java in that type bool is actually equivalent to type int. Constant true is 1 and constant false is 0. It is considered good practice, though, to write true and false in your program for boolean values rather than 1 and 0.

What is the difference between bool and Boolean in MySQL?

A Boolean is the simplest data type that always returns two possible values, either true or false. It can always use to get a confirmation in the form of YES or No value. MySQL does not contain built-in Boolean or Bool data type. They provide a TINYINT data type instead of Boolean or Bool data types.


2 Answers

bool is a built-in C++ type while BOOL is a Microsoft specific type that is defined as an int. You can find it in windef.h:

typedef int                 BOOL;  #ifndef FALSE #define FALSE               0 #endif  #ifndef TRUE #define TRUE                1 #endif 

The values for a bool are true and false, whereas for BOOL you can use any int value, though TRUE and FALSE macros are defined in the windef.h header.

This means that the sizeof operator will yield 1 for bool (the standard states, though, that the size of bool is implementation defined), and 4 for BOOL.

Source: Codeguru article

like image 162
luvieere Avatar answered Oct 03 '22 23:10

luvieere


Windows API had this type before bool was thrown into C++. And that's why it still exits in all Windows function that take BOOL. C doesn't support bool data-type, therefore BOOL has to stay.

like image 24
Ajay Avatar answered Oct 04 '22 00:10

Ajay