Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/language/bool literal"

From cppreference.com
< cpp‎ | language
m (wording)
Line 7: Line 7:
 
{{sdsc end}}
 
{{sdsc end}}
 
===Explanation===
 
===Explanation===
#boolean {{tt|true}} (a {{rlp|value_category|prvalue}} of type {{tt|bool}}. It can be implicitly converted to a prvalue of type {{tt|int}} whose value is 1)
+
#boolean {{tt|true}} (a {{rlp|value_category|prvalue}} of type {{tt|bool}}, implicitly convertible to the value 1 of type {{tt|int}}.)
#boolean {{tt|false}} (a prvalue of type {{tt|bool}}. It can be implicitly converted to a prvalue of type {{tt|int}} whose value is 0)
+
#boolean {{tt|false}} (a prvalue of type {{tt|bool}}, implicitly convertible to the value 0 of type {{tt|int}}.)
 
===Example===
 
===Example===
 
{{example|code=
 
{{example|code=

Revision as of 03:12, 23 January 2014

 
 
C++ language
General topics
Flow control
Conditional execution statements
if
Iteration statements (loops)
for
range-for (C++11)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications (until C++17*)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
const/volatile
decltype (C++11)
auto (C++11)
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
explicit (C++11)
static

Special member functions
Templates
Miscellaneous
 
 

Syntax

true (1)
false (2)

Explanation

  1. boolean true (a prvalue of type bool, implicitly convertible to the value 1 of type int.)
  2. boolean false (a prvalue of type bool, implicitly convertible to the value 0 of type int.)

Example

std::cout << std::boolalpha
          << true << '\n'
          << false << '\n'
          << std::noboolalpha
          << true << '\n'
          << false << '\n';

Output:

true
false
1
0