Skip to main content

Operator precedence and associativity in C language

Below is the table for operator precedence and associativity in C programming language.
[ ]
( )
.
->
++ --
Array subscript
Function Call
Structure reference
Structure dereference
Postfix increment/Postfix decrement


Left to right
++ --
+ -
! ~
(type)
*  &
sizeof
Prefix increment/Prefix decrement
Unary plus/Unary minus
Logical negation/One's complement
Typecast operator
Pointer dereference/Address of
Size of type/variable in bytes


Right to left
*  /  % Multiplication/Division/Modulo Left to Right
+ - Addition/Subtraction Left to Right
<<   >> Bitwise left shift/ Bitwise right shift Left to Right
<    >
<=
>=
Comparison less than/Comparision greater than
Comparison less than or equal to
Comparison greater than or equal to

Left to Right
==   != Comparison equal to/Comparison not equal to Left to Right
& Bitwise AND Left to Right
^ Bitwise XOR Left to Right
| Bitwise OR Left to Right
&& Logical AND Left to Right
|| Logical OR Left to Right
?: Ternary Conditional Operator Right to Left
=
*=    /=   %=
+=    -=
<<=   >>=
&=    ^=
|=
Assignment Operator
Mulplication/division/modulo assignment
Addition/Subtraction assignment
Bitwise left shift/right shift assignment
Bitwise AND/XOR assignment
Bitwise OR assignment


Right to Left
, Comma Operator Left to Right


Comments

Popular posts from this blog

restorecrtmode example in c

Header file:     graphics.h Synopsis:        void restorecrtmode();       Description:       restorecrtmode() restores screen mode to text mode. restorecrtmode function in c graphics   #include <graphics.h>   #include <stdlib.h>   #include <stdio.h>   #include <conio.h>   int main(void) {         /* request auto detection */         int gd = DETECT, gmode, err;         int midx, midy;         /* initialize graphics and local variables */         initgraph(&gd, &gmode, "C:/TURBOC3/BGI");         /* read result of initialization */         err = graphresult();         if (err != grOk) {                 /* an error occurred */               ...