VOOZH about

URL: https://www.geeksforgeeks.org/c/logical-operators-in-c/

⇱ C Logical Operators - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Logical Operators

Last Updated : 30 May, 2026

Logical operators in C are used to combine multiple conditions and evaluate them as a single expression. They are commonly used in decision-making statements such as if, if-else, while, and for loops to control program flow.

  • Logical operators return either 1 (true) or 0 (false) based on the evaluation of the expression.
  • They help in combining, negating, or testing multiple conditions efficiently.

Types of Logical Operators in C

C provides three logical operators:

1. Logical AND Operator ( && )

The logical AND operator (&&) returns true only if both operands are non-zero. Otherwise, it returns false (0). The return type of the result is int. Below is the truth table for the logical AND operator.

     X     

Y      X && Y     

1

1

1

1

0

0

0

1

0

0

0

0

Syntax

(operand_1 && operand_2)

Output
Both values are greater than 0

2. Logical OR Operator ( || )

The logical OR operator returns true if any one of the operands is non-zero. Otherwise, it returns false i.e., 0 as the value. Below is the truth table for the logical OR operator.

      X          Y          X || Y     

1

1

1

1

0

1

0

1

1

0

0

0

Syntax

(operand_1 || operand_2)

Output
Any one of the given value is greater than 0

3. Logical NOT Operator ( ! )

The logical NOT operator (!) reverses the result of a condition. If the condition is true, it becomes false, and if the condition is false, it becomes true. Below is the truth table for the logical NOT operator.

      X          !X     

0

1

1

0

Syntax

!(operand_1 && operand_2)

Short Circuit Logical Operators

When the result can be determined by evaluating the preceding Logical expression without evaluating the other operands, it is known as short-circuiting.

Short-circuiting can be seen in the equation having more than one Logical operator. They can either AND, OR, or both.

1. Short Circuiting in Logical AND Operator

The logical AND operator returns true only if both operands evaluate to true. If the first operand is false, the second operand is not evaluated because the overall result will always be false. This is because even if the further operands evaluate to true, the entire condition will still return false.


Output
10

2. Short Circuiting in Logical OR Operator

OR operator returns true if at least one operand evaluates to true. If the first operand is true, the second operand is not evaluated because the overall result is already true. This is because even if the further operands evaluate to false, the entire condition will still return true.


Output
This will be printed
10
Comment
Article Tags:
Article Tags: