Operators
An Operator is symbol that tells the computer to perform mathematical and other calculation. Operators are used in program to manipulate data and variable. C language support 8 types operators. Arithmetic Operators, Relational Operators, Logical Operators, Increment/Decrement Operators, Assignment Operators, Conditional Operators, Bitwise Operators, and Special Operators.
8 Types
-Arithmetic Operators + - * / %
-Relational Operators == > < != >= <=
-Logical Operators && (and) ||(or) ! (not)
-Increment/Decrement Operators ++ --
-Assignment Operators = += -= *= /= %=
-Conditional Operators ? :
-Bitwise Operators & | ^ >> << ~
-Special Operators , . -> & *
-Arithmetic Operators
+ - * / %
5+2 7
5-2 3
5*2 10
5/2 2 (5/2.0 or 5.0/2 or 5.0/2.0 ----- 2.5)
5%2 1
-Relational Operators
== > < != >= <=
5== 5 a==b
a>b
a<b
a!=b
a>=b marks>=35
a<=b
-Logical Operators
&& (and) || (or) ! (not)
T && T = T T || T = T !T = F
F && T= F F || T = T !F = T
T && F= F T || F = T
F && F= F F || F = F
-Increment/Decrement Operators ++ --
++ --
int a=5, b=0;
++a a++ --a a--
6 6 4 4
--------------------------------------------------------------
Pre Post Pre Post
b=++a b=a++ b=--a b=a--
a = 6 a=6 a=4 a=4
b = 6 b=5 b=4 b=5
-Assignment Operators
= += -= *= /= %=
Var=Constant (or) Var (or) Expression
Ex. a=5 b=2.5 x='A' ( city="Khammam")
a=d
c=(f-32)*5/9.0
a=a+2 a=a+n
a+=2 a+=n
a=a-2 a=a-n
a-=2 a-=n
a=a*2 a=a*n
a*=2 a*=n
a=a/2 a=a/n
a/=2 a/=n
a=a%2 a=a%n
a%=2 a%=n
-Conditional Operators ? :
Syntax
(Expression) ? True Statement; : False Statement;
Eg. (a>b) ? printf("A is Big"); : printf("B is Big");
-Bitwise Operators
&(and) |(pipe/or) ^(caret/XOR) >>(right shift) <<(left shift) ~(tild/negation)
int a=7, b=54, c=0
a=7 ---0000 0000 0000 0111
b=54 ---0000 0000 0011 0110
-------------------
c=a&b ---0000 0000 0000 0110
c=6
a=7 ---0000 0000 0000 0111
b=54 ---0000 0000 0011 0110
-------------------
c=a|b ---0000 0000 0011 0111
c=55
a=7 ---0000 0000 0000 0111
b=54 ---0000 0000 0011 0110
-------------------
c=a^b ---0000 0000 0011 0001
c=49
b=54 ---0000 0000 0011 0110
c=b>>2 0000 0000 0000 1101 (13)
b=54 ---0000 0000 0011 0110
c=b<<2 0000 0000 1101 1000 (216)
c=~b 1111 1111 1100 1001
-Special Operators
, . -> & *
x=(a=4,b=3,c=b-a*2)
x=-5
No comments:
Post a Comment