Namespaces
Variants

Boolean literals

From ko.cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
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
Special member functions
Templates
Miscellaneous

목차

구문

true (1)
false (2)

설명

부울 리터럴은 키워드 true 와 false 입니다. 이들은 prvalue 이며 타입은 bool 입니다.

참고 사항

다른 타입으로의 암시적 변환에 대해서는 Integral conversions 를 참조하고, bool 으로의 암시적 변환에 대해서는 boolean conversions 를 참조하십시오.

키워드

false , true

예제

#include <iostream>
int main()
{
    std::cout << std::boolalpha
              << true << '\n'
              << false << '\n'
              << std::noboolalpha
              << true << '\n'
              << false << '\n';
}

출력:

true
false
1
0

참고문헌

  • C++23 표준(ISO/IEC 14882:2024):
  • 5.13.6 불리언 리터럴 [lex.bool]
  • C++20 표준 (ISO/IEC 14882:2020):
  • 5.13.6 Boolean literals [lex.bool]
  • C++17 표준 (ISO/IEC 14882:2017):
  • 5.13.6 불리언 리터럴 [lex.bool]
  • C++14 표준(ISO/IEC 14882:2014):
  • 2.13.6 불리언 리터럴 [lex.bool]
  • C++11 표준 (ISO/IEC 14882:2011):
  • 2.13.6 불리언 리터럴 [lex.bool]
  • C++98 표준 (ISO/IEC 14882:1998):
  • 2.13.5 불리언 리터럴 [lex.bool]

참고 항목

C 문서 참조: 미리 정의된 불리언 상수