Boolean Literals

The Boolean literals represent the truth values and have only two possible values: true and false. These values are used in the Boolean expressions and logic operations.

Example

C++




// C++ program to illustrate the use of boolean literal
#include <iostream>
using namespace std;
 
int main()
{
  // using boolean literals
    bool isTrue = true;
    bool isFalse = false;
   
    if (isTrue) {
        cout << "isTrue is true" << endl;
    }
    else {
        cout << "isTrue is false" << endl;
    }
 
    if (isFalse) {
        cout << "isFalse is true" << endl;
    }
    else {
        cout << "isFalse is false" << endl;
    }
    return 0;
}


Output

isTrue is true
isFalse is false



Literals In C++

In C++ programming language, we use literals to represent fixed values. C++ supports various types of literals including integer literals, floating-point literals, character literals, and string literals. In this article, we will discuss all the necessary information on C++ literals and their usage.

Similar Reads

What are Literals in C++?

Literals are fundamental elements used to represent constant values used in C++ programming language. These constants can include numbers, characters, strings, and more. Understanding and using the literals is essential in C++ for data assignment, calculations, and data representation. They are generally present as the right operand in the assignment operation....

Types of Literals in C++

There are five types of literals in C++ which are:...

1. Integer Literals

Integer literals in C++ are constants that represent whole numbers without the fractional or decimal part. They can be positive or negative and can have different bases such as decimal, octal, or hexadecimal....

2. Floating-Point Literals

...

3. Character Literals

The Floating-point literals in C++ are constants that represent numbers with the fractional or decimal part. These can be either single-precision or double-precision values....

4. String Literals

...

5. Boolean Literals

The Character literals in C++ are constants that represent individual characters or escape sequences. They are enclosed in single quotes and you can use them to represent the single character....

Contact Us