Difference between revisions of "cpp/language/bool literal"
From cppreference.com
m (langlinks) |
m (→Keywords) |
||
(6 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
{{title|Boolean literals}} | {{title|Boolean literals}} | ||
{{cpp/language/expressions/navbar}} | {{cpp/language/expressions/navbar}} | ||
+ | |||
===Syntax=== | ===Syntax=== | ||
{{sdsc begin}} | {{sdsc begin}} | ||
− | {{sdsc | num = 1 | {{ttb|true}} }} | + | {{sdsc|num=1|{{ttb|true}}}} |
− | {{sdsc | num = 2 | {{ttb|false}} }} | + | {{sdsc|num=2|{{ttb|false}}}} |
{{sdsc end}} | {{sdsc end}} | ||
+ | |||
===Explanation=== | ===Explanation=== | ||
− | The Boolean literals are the keywords {{ | + | The Boolean literals are the keywords {{c|true}} and {{c|false}}. They are {{rlp|value category#prvalue|prvalues}} of type {{rlpt|types#Boolean type|bool}}. |
===Notes=== | ===Notes=== | ||
See {{rlp|implicit_cast#Integral_conversions|Integral conversions}} for implicit conversions from {{tt|bool}} to other types and {{rlp|implicit_cast#Boolean conversions|boolean conversions}} for the implicit conversions from other types to {{tt|bool}}. | See {{rlp|implicit_cast#Integral_conversions|Integral conversions}} for implicit conversions from {{tt|bool}} to other types and {{rlp|implicit_cast#Boolean conversions|boolean conversions}} for the implicit conversions from other types to {{tt|bool}}. | ||
+ | |||
+ | ===Keywords=== | ||
+ | {{ltt|cpp/keyword/false}}, | ||
+ | {{ltt|cpp/keyword/true}} | ||
===Example=== | ===Example=== | ||
Line 18: | Line 24: | ||
int main() | int main() | ||
{ | { | ||
− | + | std::cout << std::boolalpha | |
− | + | << true << '\n' | |
− | + | << false << '\n' | |
− | + | << std::noboolalpha | |
− | + | << true << '\n' | |
− | + | << false << '\n'; | |
} | } | ||
|output= | |output= | ||
Line 31: | Line 37: | ||
0 | 0 | ||
}} | }} | ||
+ | |||
+ | ===References=== | ||
+ | {{ref std c++23}} | ||
+ | {{ref std|section= 5.13.6|title=Boolean literals|id=lex.bool}} | ||
+ | {{ref std end}} | ||
+ | {{ref std c++20}} | ||
+ | {{ref std|section= 5.13.6|title=Boolean literals|id=lex.bool}} | ||
+ | {{ref std end}} | ||
+ | {{ref std c++17}} | ||
+ | {{ref std|section= 5.13.6|title=Boolean literals|id=lex.bool}} | ||
+ | {{ref std end}} | ||
+ | {{ref std c++14}} | ||
+ | {{ref std|section= 2.13.6|title=Boolean literals|id=lex.bool}} | ||
+ | {{ref std end}} | ||
+ | {{ref std c++11}} | ||
+ | {{ref std|section= 2.13.6|title=Boolean literals|id=lex.bool}} | ||
+ | {{ref std end}}<!-- N1804 was used for this | ||
+ | {{ref std c++03}} | ||
+ | {{ref std|section= 2.13.5|title=Boolean literals|id=lex.bool}} | ||
+ | {{ref std end}}--> | ||
+ | {{ref std c++98}} | ||
+ | {{ref std|section= 2.13.5|title=Boolean literals|id=lex.bool}} | ||
+ | {{ref std end}} | ||
+ | |||
+ | ===See also=== | ||
+ | {{dsc begin}} | ||
+ | {{dsc see c|c/language/bool_constant|Predefined Boolean constants|nomono=true}} | ||
+ | {{dsc end}} | ||
{{langlinks|de|es|fr|it|ja|pt|ru|zh}} | {{langlinks|de|es|fr|it|ja|pt|ru|zh}} |
Latest revision as of 14:58, 12 August 2024
Contents |
[edit] Syntax
true
|
(1) | ||||||||
false
|
(2) | ||||||||
[edit] Explanation
The Boolean literals are the keywords true and false. They are prvalues of type bool
.
[edit] Notes
See Integral conversions for implicit conversions from bool
to other types and boolean conversions for the implicit conversions from other types to bool
.
[edit] Keywords
[edit] Example
Run this code
#include <iostream> int main() { std::cout << std::boolalpha << true << '\n' << false << '\n' << std::noboolalpha << true << '\n' << false << '\n'; }
Output:
true false 1 0
[edit] References
- C++23 standard (ISO/IEC 14882:2024):
- 5.13.6 Boolean literals [lex.bool]
- C++20 standard (ISO/IEC 14882:2020):
- 5.13.6 Boolean literals [lex.bool]
- C++17 standard (ISO/IEC 14882:2017):
- 5.13.6 Boolean literals [lex.bool]
- C++14 standard (ISO/IEC 14882:2014):
- 2.13.6 Boolean literals [lex.bool]
- C++11 standard (ISO/IEC 14882:2011):
- 2.13.6 Boolean literals [lex.bool]
- C++98 standard (ISO/IEC 14882:1998):
- 2.13.5 Boolean literals [lex.bool]
[edit] See also
C documentation for Predefined Boolean constants
|