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?
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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With