Saturday, April 15, 2023

LOGICAL OPERATORS

 

LOGICAL OPERATORS


Logical operators in C are used to perform logical operations on Boolean values (true or false). They allow you to combine and manipulate the results of relational or logical expressions. In C, the logical operators are:

 

1. Logical AND (&&): Returns true if both operands are true; otherwise, it returns false.

   Example:

   int a = 5;

   int b = 7;

   int c = 3;

   if (a < b && b < c)

{

       // This condition is false, so the code inside the if block will not execute.

}


2. Logical OR (||): Returns true if at least one of the operands is true; otherwise, it returns false.

   Example:

   int a = 5;

   int b = 7;

   int c = 3;

   if (a < b || b < c)

{

       // This condition is true, so the code inside the if block will execute.

}


3. Logical NOT (!): Returns the opposite of the operand's logical value. If the operand is true, it returns false; if the operand is false, it returns true.

   Example:

   int a = 5;

   int b = 7;

   if (!(a < b))

{

       // This condition is false, so the code inside the if block will not execute.

 }

 

Logical operators are commonly used to combine multiple conditions in if statements, while loops, or for loops. They help you make decisions based on complex logical expressions and control the flow of your program.

BITWISE OPERATOR

  BITWISE OPERATOR In C, bitwise operators are used to perform operations at the bit level of operands. They manipulate individual bits with...