Operators & Expressions
Operators & Expressions
Operator Meaning
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal
to
== Equal to
!= Not equal to
Logical Operators
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Shift left
>> Shift right
Special operators
1. Comma operator ( ,)
2. sizeof operator – sizeof( )
3. Pointer operators – ( & and *)
4. Member selection operators – ( . and ->)
Arithmetic Expressions
Algebraic expression C expression
axb-c a*b-c
(m+n)(x+y) (m+n)*(x+y)
ab a*b/c
c
3x2+2x+1 3*x*x+2*x+1
a a/b
b
a b c S=(a+b+c)/2
S=
2
Arithmetic Expressions
Algebraic expression C expression
area= s( s a)( s b)( s c) area=sqrt(s*(s-a)*(s-b)*(s-c))
Sin
b
sin(b/sqrt(a*a+b*b))
2 2
a b
x y
1 xy
2
tow1=sqrt((rowx-rowy)/2+tow*x*y*y)
2
y
2
tow1=sqrt(pow((rowx-rowy)/2,2)+tow*x*y*y)
1 x xy
2
2
y=(alpha+beta)/sin(theta*3.1416/180)+abs(x)
y x
sin
Precedence of operators
BODMAS RULE-
Brackets of Division Multiplication Addition
Subtraction
Brackets will have the highest precedence and
have to be
evaluated first, then comes of , then comes
division, multiplication, addition and finally
subtraction.
C language uses some rules in evaluating the
expressions
and they r called as precedence rules or sometimes
also
referred to as hierarchy of operations, with some
operators
Rules for evaluation of expression
1. First parenthesized sub expression from left to right are
evaluated.
2. If parentheses are nested, the evaluation begins with the
innermost sub expression
3. The precedence rule is applied in determining the order
of application of operators in evaluating sub expressions
4. The associatively rule is applied when 2 or more
operators of the same precedence level appear in a sub
expression.
5. Arithmetic expressions are evaluated from left to right
using the rules of precedence
6. When parentheses are used, the expressions within
parentheses assume highest priority
Hierarchy of operators