Logical Operators in C Programming

Logical Operators

A Logical operator is used to compare or evaluate logical and relational expressions. There are three logical operators in the C language. They are

Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT


Used to calculate the value of logical expressions, i.e., expressions where the only values that operands can take are True or False. There are two versions of these operators. When you simply want to know if an expression is true or false (e.g., x>7), logical operators are used. These operators do not consider the structure of bits; they simply take the value 0 as false and any other value as true. There is also another version (the bitwise version) imposed by the logical operations on the bits used to internally represent the operands. These are the operators &, |, and ~, respectively.

Suppose that 'a' and 'b' are integer variables whose values are 100 and 4, respectively. Several arithmetic expressions involving these variables are shown below, together with their resulting values.

Expression Interpretation Value
(a>b)&&(a==100) True 1
(b>a)||(a>b) True 1
!(a>b) False 0

Ready to get started?

Ready to embark on your journey into the world of C programming? Our comprehensive course provides the perfect starting point for learners of all levels. With engaging lessons, hands-on exercises, and expert guidance, you'll gain the skills and confidence needed to excel in this fundamental programming language. Let's dive in and unlock the endless possibilities of C programming together!