You are on page 1of 19

C

Operator
 Arithmetic  Logical
Operator Name Operator Name
+ Addition ! NOT
- Subtraction && AND
* Multiplication || OR
/ Division
% Modulus
 Bitwise
 Relational Operator Name
Operator Name ~ Bitwise
> Greater than complement
< Less than & Bitwise AND
>= Greater than equal to | Bitwise OR
<= Less than equal to ^ Bitwise XOR
!= Not equal to << Left shift
== Equal to >> Right shift
Operator
 Assignment  Selection
Operator Name Operator Name
= Assignment ?: If-then-else
++ Increment and assign
-- Decrement and assign
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
%= Modulus and assign
|= Bitwise OR and assign
&= Bitwise AND and assign
^= Bitwise XOR and assign
<<= Left shift and assign
>>= Right shift and assign
Operator
 Operand: Operators operate on operands
 Expression: Operators and operands build expressions

(a+(b*c))/((c+d)*(b-c)) Expression
 Precedence of operator
 Unary operator: Operates on single operand
a++;
a=a+1;
 Binary operator: Operates on two operands
a+b;
 Ternary operator: Operates on three operands
?:
(condition)? True X : false Y;
c=(a<b)?a:b;
Operator
 Arithmetic operators
Operator
 Arithmetic operators
 10+25=35
 10+25.5=35.5
 10.5+25.5=36
 ‘G’+5=?
 ‘G’+‘5’=?
Operator
 Type casting
 10+25.5=35.5
Operator
 Relational operators
 Either 0 (false) or 1 (true)
Operator
 Relational operators
 a>b+c<d
 a>(b+c)<d
 a>(b+c<d)
 a>((b+c)<d)
Operator
 Logical operators
 Either 0 (false) or 1 (true)
 NOT operator
Operator
 Logical operators
 Either 0 (false) or 1 (true)
 AND operator
 Binary (A&&B)
 C=A&&B
 A,B,C=0 or 1
A B C=A&&B
0 0 0
0 1 0
1 0 0
1 1 1
Operator
 Logical operators
 Either 0 (false) or 1 (true)
 OR operator
 Binary (A||B)
 C=A||B
 A,B,C=0 or 1
A B C=A||B
0 0 0
0 1 1
1 0 1
1 1 1
Operator
 Logical operators
 Either 0 (false) or 1 (true)
Operator
 Assignment operators
 =
 ++ (increment)
• a++ (postfix) means a=a+1 (use then increment)
• ++a (prefix) means a=a+1 (increment then use)
 -- (decrement)
• a– (postfix) means a=a-1 (use then decrement)
• --a (prefix) means a=a-1 (decrement then use)
Operator
 Assignment operators
 b+=a means b=b+a
 b-=a means b=b-a
 b*=a means b=b*a
 b/=a means b=b/a
 b%=a means b=b%a
Operator
 Assignment operators
 b+=a means b=b+a
 b-=a means b=b-a
 b*=a means b=b*a
 b/=a means b=b/a
 b%=a means b=b%a
Operator
 
 Bitwise operators
 a=240, b=15
 a&&b=?


11110000
& 00001111
00000000
 a&b=0
 a|b=?
 a^b=255
11110000
XOR 00001111
11111111
Operator
 
 Bitwise operators
 a=240, b=15


 ~a=-241
11110000
00001111
 a<<1=480
11110000
111100000
 A>>1=120
Operator
 Bitwise operators

You might also like