c basic3
c basic3
Operators - An operator is a symbol that tells the compiler to perform specific mathematical or
logical functions. C language is rich in built-in operators and provides the following types of
operators
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
The following table shows all the arithmetic operators supported by the C language. Assume
variable A holds 10 and variable B holds 20 then –
Relational Operators
The following table shows all the relational operators supported by C. Assume variable A holds
10 and variable B holds 20 then −
Show Examples
== Checks if the values of two operands are equal or not. If yes, then (A == B)
the condition becomes true. is not
true.
> Checks if the value of left operand is greater than the value of right (A > B)
operand. If yes, then the condition becomes true. is not
true.
< Checks if the value of left operand is less than the value of right (A < B)
operand. If yes, then the condition becomes true. is true.
>= Checks if the value of left operand is greater than or equal to the (A >= B)
value of right operand. If yes, then the condition becomes true. is not
true.
<= Checks if the value of left operand is less than or equal to the (A <= B)
value of right operand. If yes, then the condition becomes true. is true.
Logical Operators
Following table shows all the logical operators supported by C language. Assume
variable A holds 1 and variable B holds 0, then −
Show Examples
&& Called Logical AND operator. If both the operands are non-zero, (A && B)
then the condition becomes true. is false.
Bitwise Operators
Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^
is as follows −
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
& Binary AND Operator copies a bit to the result if it exists in both (A & B) =
operands. 12, i.e.,
0000
1100
| Binary OR Operator copies a bit if it exists in either operand. (A | B) =
61, i.e.,
0011
1101
^ Binary XOR Operator copies the bit if it is set in one operand but (A ^ B) =
not both. 49, i.e.,
0011
0001
~ (~A ) =
Binary One's Complement Operator is unary and has the effect of ~(60),
'flipping' bits. i.e,. -
0111101
<< Binary Left Shift Operator. The left operands value is moved left by A << 2 =
the number of bits specified by the right operand. 240 i.e.,
1111
0000
>> Binary Right Shift Operator. The left operands value is moved right A >> 2 =
by the number of bits specified by the right operand. 15 i.e.,
0000
1111
Assignment Operators
The following table lists the assignment operators supported by the C language −