08. C – Operators Precedence

By | October 29, 2020

The precedence of operators determines which operator is executed first if there is more than one operator in an expression.

Let us consider an example:

int x = 5 - 17* 6;

In C, the precedence of * is higher than - and =. Hence, 17 * 6 is evaluated first. Then the expression involving - is evaluated as the precedence of - is higher than that of =.

Here’s a table of operators precedence from higher to lower. The property of associativity will be discussed shortly.

OperatorMeaning of operatorAssociativity
()
[]
->
.
Functional call
Array element reference
Indirect member selection
Direct member selection
Left to right
!
~
+

++

&
*
sizeof
(type)
Logical negation
Bitwise(1 ‘s) complement
Unary plus
Unary minus
Increment
Decrement
Dereference (Address)
Pointer reference
Returns the size of an object
Typecast (conversion)
Right to left
*
/
%
Multiply
Divide
Remainder
Left to right
+
Binary plus(Addition)
Binary minus(subtraction)
Left to right
<<
>>
Left shift
Right shift
Left to right
<
<=
>
>=
Less than
Less than or equal
Greater than
Greater than or equal
Left to right
==
!=
Equal to
Not equal to
Left to right
&Bitwise ANDLeft to right
^Bitwise exclusive ORLeft to right
|Bitwise ORLeft to right
&&Logical ANDLeft to right
||Logical ORLeft to right
?:Conditional OperatorRight to left
=
*=
/=
%=
+=
-=
&=
^=
|=
<<=
>>=
Simple assignment
Assign product
Assign quotient
Assign remainder
Assign sum
Assign difference
Assign bitwise AND
Assign bitwise XOR
Assign bitwise OR
Assign left shift
Assign right shift
Right to left
,Separator of expressionsLeft to right

Leave a Reply

Your email address will not be published. Required fields are marked *