title | ms.custom | ms.date | ms.technology | ms.topic | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | author | ms.author | ms.workload | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bool (C++) | Microsoft Docs |
11/04/2016 |
|
language-reference |
|
|
|
9abed3f2-d21c-4eb4-97c5-716342e613d8 |
mikeblome |
mblome |
|
This keyword is a built-in type. A variable of this type can have values true and false. Conditional expressions have the type bool and so have values of type bool. For example, i!=0
now has TRUE or FALSE depending on the value of i
.
Visual Studio 2017 version 15.3 and later (available with /std:c++17): The operand of a postfix or prefix increment or decrement operator may not be of type bool. In other words, given a variable b
of type bool, these expressions are no longer allowed:
b++;
++b;
b--;
--b;
The values TRUE and FALSE have the following relationship:
!false == true
!true == false
In the following statement:
if (condexpr1) statement1;
If condexpr1
is TRUE, statement1
is always executed; if condexpr1
is FALSE, statement1
is never executed.
When a postfix or prefix ++ operator is applied to a variable of type bool, the variable is set to TRUE. Visual Studio 2017 version 15.3 and later: operator++ for bool was removed from the language and is no longer supported.
The postfix or prefix -- operator cannot be applied to a variable of this type.
The bool type participates in integral promotions. An r-value of type bool can be converted to an r-value of type int, with FALSE becoming zero and TRUE becoming one. As a distinct type, bool participates in overload resolution.