# Boolean operators in C

The logical operators are also called Boolean operators. The name Boolean comes from George Boole, who first described the branch of mathematics that works with truth values, instead of numbers.

#### Do you learn better from video?

Learn faster with deeper understanding!
The "Computer programming for beginners" course is the perfect place to begin with programming.

## Introduction to boolean operators

C has three logical operators:

• && - logical AND, also called "conjunction"
• || - logical OR, also called "disjunction"
• ! - logical NOT

They all work with truth values and return as result truth value.

Note:If you are comming from another language like Java or C#:
Do not confuse the boolean operators && and || with the operators & and |. In C, the & and | operators are only bitwise.

## && = boolean AND = Conjunction

The boolean operator && returns true only when all its operands are true. let's visualize this:

A B A && B
false false false
false true false
true false false
true true true

which is the same as

A B A && B
0 0 0
0 1 0
1 0 0
1 1 1

## || = boolean OR = Disjunction

The logical operator || returns true, if at least one of the operands is true. If they are all false, it returns false. Here's its truth table:

A B A || B
false false false
false true true
true false true
true true true

which is equivallent to

A B A || B
0 0 0
0 1 1
1 0 1
1 1 1

#### Do you learn better from video?

Learn faster with deeper understanding!
The "Computer programming for beginners" course is the perfect place to begin with programming.

## ! = Logical NOT = Negation

The negation always returns the opposite of its operand. NOT true is false. NOT false is true. Simple logic ;)

 Previous: switch Next: Loops in C
 Did this help? Support me with your vote ;-)
 Did this help?

› Boolean operators