Relational operators

The following table shows all the relational operators supported by C language. Assume variable A holds 10 and variable B holds 20 then

Operator Description Example
== Checks if the value of two operands are equal or not. If yes, then the condition becomes true. A == B is not true.
!= Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. A != B is true.
> Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. A > B is not true.
< Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. A < B is true
>= Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. A >= B is not true
<= Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. A <= B is true.

Logical Operators

The logical operators are used to test more than one condition, and these are used to combine 2 or more expressions logically. They are

  1. && (Logical AND)
  2. || (Logical OR)
  3. ! (Logical NOT)

&& (Logical AND)

Expression 1 Expression 2 Expression 1 && Expression 2
0 0 0
1 0 0
0 1 0
1 1 1

|| (Logical OR)

Expression 1 Expression 2 Expression 1 && Expression 2
0 0 0
1 0 1
0 1 1
1 1 1

! (Logical NOT)

Expression ! Expression
0 1
1 0

Bitwise Logical Operators

The following table lists the Bitwise operators supported by C. Assume variable 'a' holds 60 and variable 'B' holds 13.

Operator Description Example
& Binary AND Operator copies a bit to the result if it exists in both operands. A & B = 12
| Binary OR Operator copies a bit if it exists in either operand. A | B = 61
^ Binary XOR Operator copies the bit if it is set in one operand but not both. A ^ B = 49
~ Binary One's complement Operator is uanry and has the effect of flipping bits. ~A = ~(60)
<< Bianry Left Shift Operator. The left operasnds value is moved left by the number of bits specified by the right operand. A << 2 = 240
>> Binary Right shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A >> 2 = 15