[Main]
Title=Precedence of Operators

[Top]
In the following table of operator precedence, the C operators are
divided into 15 categories. The #1 category has the highest precedence;
category #2 (Unary operators) takes second precedence, and so on to the
Comma operator, which has lowest precedence. The operators within each
category have equal precedence.
<BR><BR>
The Unary (category #2), Conditional (category #13), and Assignment
(category #14) operators associate right-to-left; all other operators
associate left-to-right.
<BR><BR>
<TABLE BORDER CELLPADDING="5">
<TR><TD><B>Category</B></TD><TD><B>Operator</B></TD><TD><B>What it is (or does)</B></TD></TR>
<TR>
<TD VALIGN="TOP">1.&nbsp;Highest</TD>
<TD>
 [&nbsp;]<BR>
 (&nbsp;)<BR>
-&gt;<BR>
.
</TD>
<TD>
<A HREF="$$LINK(subscr)">Array&nbsp;subscript</A><BR>
<A HREF="$$LINK(parentheses)">Function&nbsp;call</A><BR>
<A HREF="$$LINK(select)">Indirect&nbsp;component&nbsp;selector</A><BR>
<A HREF="$$LINK(select)">Direct&nbsp;component&nbsp;selector</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">2.&nbsp;Unary</TD>
<TD>
!<BR>
~<BR>
+<BR>
-<BR>
++<BR>
--<BR>
&amp;<BR>
*<BR>
sizeof<BR>
(<I>type</I>)
</TD>
<TD>
<A HREF="$$LINK(logneg)">Logical&nbsp;negation&nbsp;(NOT)</A><BR>
<A HREF="$$LINK(complement)">Bitwise&nbsp;(1's)&nbsp;complement</A><BR>
<A HREF="$$LINK(unarypm)">Unary&nbsp;plus</A><BR>
<A HREF="$$LINK(unarypm)">Unary&nbsp;minus</A><BR>
<A HREF="$$LINK(inc)">Preincrement&nbsp;or&nbsp;postincrement</A><BR>
<A HREF="$$LINK(dec)">Predecrement&nbsp;or&nbsp;postdecrement</A><BR>
<A HREF="$$LINK(ref)">Address</A><BR>
<A HREF="$$LINK(deref)">Indirection</A><BR>
<A HREF="$$INFOLINK(keywords/sizeof)">Size&nbsp;of&nbsp;operand,&nbsp;in&nbsp;bytes</A><BR>
<A HREF="$$LINK(cast)">TypeCast</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">3.&nbsp;Multiplicative</TD>
<TD>
*<BR>
/<BR>
%<BR>
</TD>
<TD>
<A HREF="$$LINK(mult)">Multiply</A><BR>
<A HREF="$$LINK(mult)">Divide</A><BR>
<A HREF="$$LINK(mult)">Remainder&nbsp;(modulus)</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">4.&nbsp;Aditive</TD>
<TD>
+<BR>
-
</TD>
<TD><A HREF="$$LINK(binpm)">Binary&nbsp;plus</A><BR>
<A HREF="$$LINK(binpm)">Binary&nbsp;minus</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">5.&nbsp;Shift</TD>
<TD>
&lt;&lt;<BR>
&gt;&gt;
</TD>
<TD>
<A HREF="$$LINK(shift)">Shift&nbsp;left</A><BR>
<A HREF="$$LINK(shift)">Shift&nbsp;right</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">6.&nbsp;Relational</TD>
<TD>
&lt;<BR>
&lt;=<BR>
&gt;<BR>
&gt;=
</TD>
<TD>
<A HREF="$$LINK(relop)">Less&nbsp;than</A><BR>
<A HREF="$$LINK(relop)">Less&nbsp;than&nbsp;or&nbsp;equal&nbsp;to</A><BR>
<A HREF="$$LINK(relop)">Greater&nbsp;than</A><BR>
<A HREF="$$LINK(relop)">Greater&nbsp;than&nbsp;or&nbsp;equal&nbsp;to</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">7.&nbsp;Equality</TD>
<TD>
==<BR>
!=
</TD>
<TD>
<A HREF="$$LINK(equ)">Equal&nbsp;to</A><BR>
<A HREF="$$LINK(equ)">Not&nbsp;equal&nbsp;to</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">8.</TD>
<TD>
&amp;
</TD>
<TD>
<A HREF="$$LINK(logbit)">Bitwise&nbsp;AND</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">9.</TD>
<TD>
^
</TD>
<TD>
<A HREF="$$LINK(logbit)">Bitwise&nbsp;XOR</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">10.</TD>
<TD>
|
</TD>
<TD>
<A HREF="$$LINK(logbit)">Bitwise&nbsp;OR</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">11.</TD>
<TD>
&amp;&amp;
</TD>
<TD>
<A HREF="$$LINK(logbit)">Logical&nbsp;AND</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">12.</TD>
<TD>
||
</TD>
<TD>
<A HREF="$$LINK(logbit)">Logical&nbsp;OR</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">13.&nbsp;Conditional</TD>
<TD>
?&nbsp;:
</TD>
<TD>
<A HREF="$$LINK(cond)">"a&nbsp;?&nbsp;x&nbsp;:&nbsp;y"&nbsp;means&nbsp;"if&nbsp;a&nbsp;then&nbsp;x,&nbsp;else&nbsp;y"</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">14.&nbsp;Assignment</TD>
<TD>=<BR>
*=<BR>
/=<BR>
%=<BR>
+=<BR>
-=<BR>
&amp;=<BR>
^=<BR>
|=<BR>
&lt;&lt;=<BR>
&gt;&gt;=
</TD>
<TD>
<A HREF="$$LINK(assign)">Simple&nbsp;assignment</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;product</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;quotient</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;remainder&nbsp;(modulus)</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;sum</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;difference</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;bitwise&nbsp;AND</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;bitwise&nbsp;XOR</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;bitwise&nbsp;OR</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;left&nbsp;shift</A><BR>
<A HREF="$$LINK(assign)">Assign&nbsp;right&nbsp;shift</A>
</TD>
</TR>
<TR>
<TD VALIGN="TOP">15.&nbsp;Comma</TD>
<TD>
,
</TD>
<TD>
<A HREF="$$LINK(comma)">Evaluate</A>
</TD>
</TR>
</TABLE>
