What are boolean literals in D programming?
What are literals?
Literals are values of variables that cannot be changed after definition.
Types of literals in D
There are five types of literals in D programming:
- Integer numerals
- Floating-point numerals
- Characters
- Strings
- Boolean values
In this shot, we will focus on the boolean literal.
What are boolean literals?
Boolean literals convey the boolean logic, which means that there are two boolean literals:
- True
- False
True should not be assumed to have the value 1 and false should not be assumed to have the value 0. These boolean literals are the same as the standard D keywords true and false.
Example
import std.stdio;bool boolval = true;int main(){writeln(boolval);return 0;}
Explanation
Line 2: We define a boolean variable called boolval.
Line 6: Inside the main function, we print the value that boolval contains, which is true.