> For the complete documentation index, see [llms.txt](https://mr-poston-1.gitbook.io/c++/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mr-poston-1.gitbook.io/c++/1.-c++-basics/1.3-conditional-statements/1.3.4-logical-operators.md).

# 1.3.4 Logical Operators

Logical operators are operators such as and, or, and not. You should be familiar with these concepts from previous computer science courses, and in C++ they work exactly the same.

### And

The **and** operator is denoted with `&&`, the same as Java. Any conditions joined with an and operator must both be true for the expression to be true.

### Or

The **or** operator is denoted with `||`, again the same as Java. For an or expression to return true, either of the expressions need to be true, It is ok if both are also true.

### Not

The **not** operator is again the same as Java, `!`. When applied to a boolean value, it returns the opposite value. For example, *not true* returns false.

Notice in this example how logical operators are used as the conditional statement for the `if` block. Since logical operators ultimately evaluate to a true/false value, they can be used as the condition for an `if` block.

Alternatively, you can set up your code with nested `if` statements.

### Try This Example

{% embed url="<https://onlinegdb.com/Z9w7VEH4L>" %}
Logical Operators
{% endembed %}
