C Programming Operator Precedence and Associativity
 |
C Programming supports wide range of Operators . While Solving the Expression we must follow some rules , Example : while Solving the expression [ a + b *c ] , we should first perform Multiplication Operation and then Addition . Similarly in order to solve such complicated expression you should have hands on Operator Precedence and Associativity of Operators. Precedence of the Operator are Listed in the Following Table and This Table is Summarized in decreasing Order of Priority i.e Topmost Operator has Highest Priority and Bottommost Operator has Lowest Priority. |
| Description |
Operator |
Associativity |
Increment Decrement Negation Unary Minus Sizeof |
++ – ! - sizeof |
R -> L |
Multiplication Division Modulus |
* / % |
L -> R |
Addition Subtraction |
+ - |
L -> R |
Shift Operator
|
<< >> |
L -> R |
Less Than Greater Than Less Than and Equal to Greater Than and Equal to |
< > <= >= |
L -> R |
Equal to Not Equal To |
== != |
L -> R |
| Logical AND |
&& |
L -> R |
| Logical OR |
|| |
L -> R |
| Conditional |
?: |
R -> L |
| Assignment |
= += -= *= /= |
R -> L |
| Comma |
, |
L -> R |
Notes :
- Comma Operator Has Lowest Precedence .
- Unary Operators are Operators having Highest Precedence.
- Sizeof is Operator not Function .
- Operators sharing Common Block in the Above Table have Equal Priority or Precedence .
- While Solving Expression , Equal Priority Operators are handled on the basis of FIFO [ First in First Out ] i.e Operator Coming First is handled First.
Some Definitions :
| Unary Operator : |
- A unary operation is an operation with only one operand, i.e. an operation with a single input .
- A unary operator is one which has only one operand. e.g.
post / pre increment operator.
|
| Binary Operator |
- A Binary operator is one which has two operand. e.g.
plus , Minus .
|
Important Terms :
| Associativity |
- Their associativity indicates in what order operators of equal precedence in an expression are applied
|
| Precedence |
|
Related Articles:
- Arrow Operator : Accessing Structure members using Pointer
- Bitwise Right Shift Operator in C
- Bitwise Operators in C : Index
- Pointers in C Programming : Learn Pointer Tutorials
- One’s Compliment Operator in C
About the author: Pritesh View all posts by Pritesh
My name is Pritesh Taral. I am working in well known MNC. as Java Developer. I am part time blogger loves writing articles on C/C++.
I am active on facebook using community fan page .One can Visit me @ Facebook
Facebook Fan Page