1 | Unary Postfix | ++ --
Suffix/postfix increment and decrement, e.g., var++; . ()
Function call, e.g., func (param) . []
Array subscripting, e.g., x=X[1]; . .
Structure and union member access, e.g., x=Param.x; . ->
Structure and union member access through pointer, e.g., x=this->x; . (type){list}
Compound literal (C99), e.g., int *p = (int[]){2, 4}; | Left to rightUnary postfix operators always associate left-to-right (a[1][2]++ is ((a[1])[2])++ ). Note that the associativity is meaningful for member access operators, even though they are grouped with unary postfix operators: a.b++ is parsed (a.b)++ and not a.(b++) . |
2 | Unary Prefix | ++ --
Prefix increment and decrement, e.g., ++var; . + -
Unary plus and minus, e.g., a=b+1; . ! ~
Logical NOT and bitwise NOT, e.g., a=!b; . (type)
Type cast, e.g., float x = (float)y; . *
Indirection (dereference), e.g., float x = *(float *)&y; . &
Address-of, e.g., float x = *(float *)&y; . sizeof
Size-of, e.g., sizeof (int) * p is (sizeof(int)) * p . | Right to leftUnary prefix operators always associate right-to-left (sizeof ++*p is sizeof(++(*p)) ). |
3 | Binary | * / %
Multiplication, division, and remainder, e.g., x=a*b/c%d is x=((a*b)/c)%d . | Left to right |
4 | Binary | + -
Addition and subtraction, e.g., x=a+b-c is x=(a+b)-c . | Left to right |
5 | Binary | << >>
Bitwise left shift and right shift, e.g., x=a>>1<<1 is x=(a>>1)<<1 . | Left to right |
6 | Binary | < <=
For relational operators < and ≤ respectively. > >=
For relational operators > and ≥ respectively. | Left to right |
7 | Binary | == !=
For relational = and ≠ respectively. | Left to right |
8 | Binary | &
Bitwise AND. | Left to right |
9 | Binary | ^
Bitwise XOR (exclusive or). | Left to right |
10 | Binary | |
Bitwise OR (inclusive or). | Left to right |
11 | Binary | &&
Logical AND. | Left to right |
12 | Binary | ||
Logical OR, e.g., x = a && b || c && d is x = (a&&b) || (c&&d) . | Left to right |
13 | Ternary | ?:
Ternary conditional. The expression in the middle of the conditional operator (between ? and : ) is parsed as if it is parenthesized: its precedence relative to ?: is ignored. | Right to left |
14 | Assign | =
Simple assignment. The expression a=b=c is parsed as a=(b=c), and not as (a=b)=c because of right-to-left associativity. += -=
Assignment by sum and difference. *= /= %=
Assignment by product, quotient, and remainder. <<= >>=
Assignment by bitwise left shift and right shift. &= ^= |=
Assignment by bitwise AND, XOR, and OR. | Right to left |
15 | Comma | ,
Comma. | Left to right |
0 Comments