Operators

An operator is a symbol that specifies the operation to be performed on an instance. The operator performs an operation on the operand and returns an instance of the result.


Table of contents:


Priority

Change priority

Priority

Operators have priorities. Expressions containing multiple operators are operated in the order determined by precedence and associativity.

The following is a list of operators. The smaller number is the higher priority.


Priority 1
()x(y)Method call operator
newnew int()new operator
thisthisthis operator
[]x[y]Indexer operator
Priority 2
.x.yDot operator
++x++Postfix ++ operator
--x--Postfix -- operator
Priority 3
++xUnary + operator
--xUnary - operator
!!xLogical negation operator
++++xPrefix ++ operator
----xPrefix -- operator
Priority 4
*x * yMultiplication operator
/x / yDivision operator
%x % yModulo operator
Priority 5
+x + yAddition operator
-x - ySubtraction operator
Priority 6
<x < yLess than operator
<=x <= yLess than or equal operator
>x > yGreater than operator
>=x >= yGreater than equal operator
Priority 7
==x == yValue equality operator
!=x != yValue inequality operator
$$x $$ yReference equality operator
!$x !$ yReference inequality operator
Priority 8
&x & yLogical AND operator
Priority 9
|x | yLogical OR operator

Change priority

You can change the priority of operations by using parentheses. Expressions in parentheses are preferentially operated.


int i = (2 + 2) * 2; // 8

Copyright © Rice All rights reserved.