Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

C Logical operator

The document provides an overview of logical and bitwise operators in C programming. It explains the functionality of logical operators (AND, OR, NOT) and their syntax, along with examples demonstrating their use. Additionally, it introduces bitwise operators (AND, OR, XOR) and describes their operations at the bit level for efficient processing.

Uploaded by

neeraj.bhopal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

C Logical operator

The document provides an overview of logical and bitwise operators in C programming. It explains the functionality of logical operators (AND, OR, NOT) and their syntax, along with examples demonstrating their use. Additionally, it introduces bitwise operators (AND, OR, XOR) and describes their operations at the bit level for efficient processing.

Uploaded by

neeraj.bhopal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1/26/25, 6:19 PM Operators in C - GeeksforGeeks

3. Logical Operator in C
Logical Operators are used to combine two or more
conditions/constraints or to complement the evaluation of the original
condition in consideration. The result of the operation of a logical
operator is a Boolean value either true or false.

S. No. Symbol Operator Description Syntax

1 Returns true if
both the
&& Logical AND a && b
operands are
true.

2 Returns true if

|| both or any of a || b
Logical OR
the operand is
true.

3 Returns true if
! Logical NOT the operand is !a
false.

Example of Logical Operators in C

1 // C program to illustrate the logical operators


2 #include <stdio.h>
3
4 int main()
5 {
6
7 int a = 25, b = 5;
8
9 // using operators and printing results
10 printf("a && b : %d\n", a && b);
11 printf("a || b : %d\n", a || b);
12 printf("!a: %d\n", !a);
13

https://www.geeksforgeeks.org/operators-in-c/ 7/27
1/26/25, 6:19 PM Operators in C - GeeksforGeeks

return 0;
15 }

Output

a && b : 1
a || b : 1
!a: 0

4. Bitwise Operators in C
The Bitwise operators are used to perform bit-level operations on the
operands. The operators are first converted to bit-level and then the
calculation is performed on the operands. Mathematical operations such
as addition, subtraction, multiplication, etc. can be performed at the bit
level for faster processing.

There are 6 bitwise operators in C:

S. No. Symbol Operator Description Syntax

1 Performs bit-
by-bit AND
& Bitwise AND operation and a&b
returns the
result.

2 Performs bit-
by-bit OR
| Bitwise OR operation and a|b
returns the
result.

3 Performs bit-
by-bit XOR
^ Bitwise XOR operation and a^b
returns the
result.

https://www.geeksforgeeks.org/operators-in-c/ 8/27

You might also like