intx=5;inty=3;printf("%d",x>y);// returns 1 (true) because 5 is greater than 3
Symbol
Name
Example
==
equals
x == y
!=
not equal to
x != y
>
greater than
x > y
<
less than
x < y
>=
greater than or equal to
x >= y
<=
less than or equal to
x <= y
Comparison operators are used to compare two values
Logical Operators
Symbol
Name
Description
Example
&&
and logical
returns true if both statements are true
x < 5 && x < 10
||
or logical
returns true if one of the statements is true
x < 5 || x < 4
!
not logical
Invert result, return false if true
!(x < 5 && x < 10)
Operator Examples
unsignedinta=60;/*60 = 0011 1100 */unsignedintb=13;/*13 = 0000 1101 */intc=0;c=a&b;/*12 = 0000 1100 */printf("Line 1 -the value of c is %d\n",c);c=a|b;/*61 = 0011 1101 */printf("Line 2 -the value of c is %d\n",c);c=a^b;/*49 = 0011 0001 */printf("Line 3 -the value of c is %d\n",c);c=~a;/*-61 = 1100 0011 */printf("Line 4 -The value of c is %d\n",c);c=a<<2;/*240 = 1111 0000 */printf("Line 5 -the value of c is %d\n",c);c=a>>2;/*15 = 0000 1111 */printf("Line 6 -The value of c is %d\n",c);
Bitwise operators
Operator
Description
Instance
&
Bitwise AND operation, "AND" operation by binary digits
(A & B) will get 12 which is 0000 1100
|
Bitwise OR operator, "or" operation by binary digit
(A | B) will get61 which is 0011 1101
^
XOR operator, perform "XOR" operation by binary digits
(A ^ B) will get 49 which is 0011 0001
~
Inversion operator, perform "inversion" operation by binary bit