The ISO/ANSI C++ Standard has added certain new data types to the original C++ specifications.They are provided to provide better control in certain situations as well as for providing conveniences to C++ programmers.
One of the new data type is: bool
bool b1 = true; // declaring a boolean variable with true value
In C++, the data type bool has been introduced to hold a boolean value, true or false.The values true or false have been added as keywords in the C++ language.
- The default numeric value of true is 1 and false is 0.
- We can use bool type variables or values true and false in mathematical expressions also.For instance,
int x = false + true + 6;
is valid and the expression on right will evaluate to 7 as false has value 0 and true will have value 1.
- It is also possible to convert implicitly the data type integers or floating point values to bool type. For example, the statements-
x = 0;
y = 100;
z = 15.75;
b1 is = 0 b2 is = 1 Yes 9
Related article: How to use Bool in C?
This article is contributed by Mrigendra Singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Is there any need of "long" data type in C and C++?
- What is the size_t data type in C?
- Data Type Ranges and their macros in C++
- C++ map having key as a user define data type
- C++ set for user define data type
- Data type of character constants in C and C++
- Comparison of boolean data type in C++ and Java
- Multi-set for user defined data type
- Conversion of Struct data type to Hex String and vice versa
- Type Conversion in C++
- Type of 'this' pointer in C++
- Array Type Manipulation in C++
- Can a C++ class have an object of self type?
- reinterpret_cast in C++ | Type Casting operators
- C++ program to find the type of the given iterator