
- D Programming Basics
- D Programming - Home
- D Programming - Overview
- D Programming - Environment
- D Programming - Basic Syntax
- D Programming - Variables
- D Programming - Data Types
- D Programming - Enums
- D Programming - Literals
- D Programming - Operators
- D Programming - Loops
- D Programming - Decisions
- D Programming - Functions
- D Programming - Characters
- D Programming - Strings
- D Programming - Arrays
- D Programming - Associative Arrays
- D Programming - Pointers
- D Programming - Tuples
- D Programming - Structs
- D Programming - Unions
- D Programming - Ranges
- D Programming - Aliases
- D Programming - Mixins
- D Programming - Modules
- D Programming - Templates
- D Programming - Immutables
- D Programming - File I/O
- D Programming - Concurrency
- D Programming - Exception Handling
- D Programming - Contract
- D - Conditional Compilation
- D Programming - Object Oriented
- D Programming - Classes & Objects
- D Programming - Inheritance
- D Programming - Overloading
- D Programming - Encapsulation
- D Programming - Interfaces
- D Programming - Abstract Classes
- D Programming - Useful Resources
- D Programming - Quick Guide
- D Programming - Useful Resources
- D Programming - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
D Programming - Logical Operators
The following table shows all the logical operators supported by D language. Assume variable A holds 1 and variable B holds 0, then −
Operator | Description | Example |
---|---|---|
&& | It is called Logical AND operator. If both the operands are non-zero, then condition becomes true. | (A && B) is false. |
|| | It is called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true. | (A || B) is true. |
! | It is called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. | !(A && B) is true. |
Example
Try the following example to understand all the logical operators available in D programming language −
import std.stdio; int main(string[] args) { int a = 5; int b = 20; int c ; if ( a && b ) { writefln("Line 1 - Condition is true\n" ); } if ( a || b ) { writefln("Line 2 - Condition is true\n" ); } /* lets change the value of a and b */ a = 0; b = 10; if ( a && b ) { writefln("Line 3 - Condition is true\n" ); } else { writefln("Line 3 - Condition is not true\n" ); } if ( !(a && b) ) { writefln("Line 4 - Condition is true\n" ); } return 0; }
When you compile and execute the above program it produces the following result −
Line 1 - Condition is true Line 2 - Condition is true Line 3 - Condition is not true Line 4 - Condition is true
d_programming_operators.htm
Advertisements