Operators and Expressions 41
3.2 PRIORITY OF OPERATORS AND THEIR CLUBBING
Various relational operators have different priorities or precedence. If an arithmetic expression
contains more operators then the execution will be performed according to their priorities. The
precedence is set for different operators in C.
List of operators with priority wise (hierarchical) are shown in Table 3.2.
Table 3.2 List of operators with priority wise
Operators
Operation Clubbing Priority
0
Function call Left to right
1st
[]
Array expression or square bracket
-
> Structure Operator
Structure Operator
+
Unary plus
Right to left
2nd
-
Unary minus
++
Increment
Decrement
I Not operator
-
Ones complement
*
Pointer Operator
&
Address Operator
sizeof
Size of an object
type
Type cast
*
Multiplication
Left to right 3rd
/
Division
%
Modular division
+
Addition
Left to right
4th
-
Subtraction
<<
Left shift
Left to right
5th
>>
Right shift
<
Less than
Left to right
6th
<=
Less than or equal to
>
Greater than
>=
Greater than or equal to
== Equality
Left to right
yth
1 =
Inequality
&
Bitwise AND
Left to right
8th
A
Bitwise XOR
Left to right
gth
1
Bitwise OR
Left to right
19,h
42 Programming and Data Structures
&& Logical AND
Left to right
11th
| | Logical OR
Left to right
12th
?: Conditional operator
Right to left
13th
=, *»,- =/ &=,+*
, |«, <<=, >>= Assignment Operators
Right to left 14th
Comma operator Left to right
15th
1) When two operators of the same priority are found in the expression, precedence is given to
the extreme left operator.
Example x= 5
2;
3
Here, 5*4 is solved first. Though * and / have the same priorities. The operator * occurs before /.
2) If there are more sets of parenthesis in the expression, the innermost parenthesis will be solved
first, followed by the second and so on.
Example ( 8 / ( 2 * ( 2 * 2 )));
1
2
3
Here,
a) Innermost bracket is evaluated first i.e. 2*2=4.
b) Second innermost bracket is evaluated. 2 is multiplied with result of innermost bracket. The
answer of 2*4=8.
c) The outer most is evaluated. 8 is divided by 8 and gives result 1.
Example
X k =
u
1
5
8
7
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.170.187