Previous section To contents Next section

5.8 Operator precedence

When evaluating an expression, you can always use parenthesis to tell the compiler in which order to evaluate things. Normally, the compiler will evaluate things from left to right, but it will evaluate operators with higher priority before those with lower. The following table shows the relative priority of all the operators in descending order:

(a) a() a[b] a->b a[b..c] ({}) ([]) (<>)
!a ~a (type)a ++a --a
a++ a--
a*b a/b a%b
a+b a-b
a>>b a<<b
a>b a>=b a<b a<=b
a==b a!=b


The expression is evaluated in this order:
1+2*2   1+(2*2)
1+2*2*4   1+((2*2)*4)
(1+2)*2*4   ((1+2)*2)*4
1+4,c=2|3+5   (1+4),(c=((2|3)+5))
1+5 & 4 == 3   (1+(5 & 4)) == 3
c=1,99   (c=1),99
!a++ + ~--a()  (!(a++)) + (~((--a)()))

Previous section To contents Next section