% Precedence of operators in C++. \documentstyle[a4,12pt,lgrind,nick,array]{article} \pagestyle{empty} \setlength{\extrarowheight}{1.5pt} \newcommand{\cm}{,\,\,} \begin{document} \begin{center} {\huge\bf Operator Precedence and Associativity} \vspace{3ex} % Turn off special handling of vertical bar, else trouble in tabular: %|- % Turn off special handling of ampersand, else trouble with amp % amp: % % There is another bug in lgrind. If there is a `%' anywhere on a % line, then anywhere after that there can be no ampersand unless % that ampersand is to be treated literally. % Notice the use of \textsf{} to work around this problem. % Also, the `%=' operator had to be moved from the beginning of one % line to the end of the previous line. \begin{tabular}{|l|c|l|} \hline \multicolumn{1}{|c|}{\em Level} & \multicolumn{1}{c|}{\em Operator} & \multicolumn{1}{c|}{\em Function} \\ \hline 17R & @::@ & global scope (unary) \\ 17L & @::@ & class scope (binary) \\ \hline 16L & @->@\cm@.@ & member selectors \\ 16L & @[]@ & array index \\ 16L & @()@ & function call \\ 16L & @()@ & type construction \\ \hline 15R & @sizeof@ & size in bytes \\ 15R & @++@\cm@--@ & increment, decrement \\ 15R & @~@ & bitwise NOT \\ 15R & @!@ & logical NOT \\ 15R & @+@\cm@-@ & unary plus, minus \\ 15R & @*@\cm@&@ & dereference, address-of \\ 15R & @()@ & type conversion (cast) \\ 15R & @new@, @delete@ & heap management \\ \hline 14L & @->*@\cm@.*@ & member pointer selectors \\ \hline 13L & @*@\cm@/@\cm\textsf{\%} & multiplicative operators \\ \hline 12L & @+@\cm@-@ & arithmetic operators \\ \hline 11L & @<<@\cm@>>@ & bitwise shift \\ \hline 10L & @<@\cm@<=@\cm@>@\cm@>=@ & relational operators \\ \hline 9L & @==@\cm@!=@ & equality, inequality \\ \hline 8L & @&@ & bitwise AND \\ \hline 7L & @^@ & bitwise XOR \\ \hline 6L & @|@ & bitwise OR \\ \hline 5L & @&&@ & logical AND \\ \hline 4L & @||@ & logical OR \\ \hline 3L & @?:@ & arithmetic if \\ \hline 2R & @=@\cm@*=@\cm@/=@\cm\textsf{\%=} & assignment operators \\ & \textsf{+=}\cm\textsf{$-$=}\cm@<<=@ & \\ & @>>=@\cm@&=@\cm@|=@\cm@^=@ & \\ \hline 1L & @,@ & comma operator \\ \hline \end{tabular} \end{center} \vspace{2ex} {\footnotesize This is taken from table 2.4, p. 87 of Stanley B. Lippman, {\em \Cpp\ Primer}, Addison-Wesley, 1992.} \end{document}